﻿attachedElements = {}
function guiAttachToDirectX(to,element,x,y)
	table.insert(attachedElements,{to,element,x,y})
end
function toHex(x)
	return string.format("%x",x)
end

function intersect(x,y,x2,y2,posx,posy)
	if (posx >= x and posx<=x2) and (posy >= y and posy<=y2) then
		return true
	end
	return false
end

function string:tobool()
	if self == "true" then
		return true
	else
		return false
	end
end

function relativeToAbsolute(xcoord,ycoord)
	local x,y = guiGetScreenSize()
	local rx = x*xcoord
	local ry = y*ycoord
	return rx,ry
end

function getCursorAbsolute()
	local scx,scy,wx,wy,wh = getCursorPosition()
	local x,y = relativeToAbsolute(scx,scy)
	return x,y
end

function dxCreateRootPane()
	local element = createElement("dxRootPane")
	local screenX,screenY = guiGetScreenSize()
	setElementData(element,"x",0)
	setElementData(element,"y",0)
	setElementData(element,"width",screenX)
	setElementData(element,"height",screenY)
	setElementData(element,"theme",dxGetDefaultTheme())
	setElementData(element,"visible",true)
	setElementData(element,"container",true)
	return element
end

function dxGetRootPane()
	for _,root in ipairs(getElementsByType("dxRootPane")) do
		return root
	end
	return dxCreateRootPane()
end

function dxRefreshThemes()
	for _,theme in ipairs(getElementsByType("dxTheme")) do
		destroyElement(theme)
	end
	
	local xml = xmlLoadFile("dxGui/themes.xml")
	local defaultsel = false
	local i = 0
	while (xmlFindChild(xml,"theme",i)) do
		local theme_c = xmlFindChild(xml,"theme",i)
		local theme = createElement("dxTheme")
		if (xmlNodeGetAttribute(theme_c,"default")) then
			setElementData(theme,"default",true)
		else
			setElementData(theme,"default",false)
		end
		setElementData(theme,"name",xmlNodeGetAttribute(theme_c,"name"))
		
		local theme_im = xmlFindChild(theme_c,"images",0)
		local theme_ims = xmlFindChild(theme_c,"imagesets",0)
		
		setElementData(theme,"images","dxGui/"..xmlNodeGetAttribute(theme_c,"name").."/"..xmlNodeGetAttribute(theme_im,"src"))
		setElementData(theme,"imagesets","dxGui/"..xmlNodeGetAttribute(theme_c,"name").."/"..xmlNodeGetAttribute(theme_ims,"src"))
		
		local xml2 = xmlLoadFile("dxGui/"..xmlNodeGetAttribute(theme_c,"name").."/"..xmlNodeGetAttribute(theme_ims,"src"))
		local i_ = 0
		while (xmlFindChild(xml2,"Image",i_)) do
			local image_c = (xmlFindChild(xml2,"Image",i_))
			local name = xmlNodeGetAttribute(image_c,"Name")
			setElementData(theme,name..":Height",tonumber(xmlNodeGetAttribute(image_c,"Height")))
			setElementData(theme,name..":Width",tonumber(xmlNodeGetAttribute(image_c,"Width")))
			setElementData(theme,name..":X",tonumber(xmlNodeGetAttribute(image_c,"XPos")))
			setElementData(theme,name..":Y",tonumber(xmlNodeGetAttribute(image_c,"YPos")))
			if xmlNodeGetAttribute(image_c,"Image") then
				setElementData(theme,name..":images","dxGui/"..xmlNodeGetAttribute(theme_c,"name").."/"..xmlNodeGetAttribute(image_c,"Image"))
			else
				setElementData(theme,name..":images",getElementData(theme,"images"))
			end
			i_ = i_+1
		end
		i=i+1
	end
end

function dxGetTheme(themeName)
	for _,theme in ipairs(getElementsByType("dxTheme")) do
		if getElementData(theme,"name") == themeName then
			return theme
		end
	end
	return false
end

function dxGetDefaultTheme()
	theme = false
	for _,themes in ipairs(getElementsByType("dxTheme")) do
		if (getElementData(themes,"default")) then
			theme = themes
			break
		end
	end
	return theme
end

addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),
	function(resource)
		if resource == getThisResource() then
			dxRefreshThemes()
			dxCreateRootPane()
		end
	end
)

function dxWindowGetTitlePosition(dxElement,relative)
	if not dxElement then
		outputDebugString("dxWindowGetTitlePosition gets wrong parameters (dxElement[,relative=false])")
		return
	end
	if (getElementType(dxElement)~="dxWindow") then
		outputDebugString("dxWindowGetTitlePosition gets wrong parameters (dxElement must be dxWindow)")
		return
	end

	local tx,ty = getElementData(dxElement,"Title:x"),getElementData(dxElement,"Title:y")
	local px,py = getElementData(getElementParent(dxElement),"width"),getElementData(getElementParent(dxElement),"height")
	if relative then
		return tx/px,ty/py
	else
		return tx,ty
	end
end

function dxWindowSetTitlePosition(dxElement,x,y,relative)
	if not dxElement or not x or not y then
		outputDebugString("dxGetPosition gets wrong parameters (dxElement,x,y[,relative=false])")
		return
	end
	if (getElementType(dxElement)~="dxWindow") then
		outputDebugString("dxGetPosition gets wrong parameters (dxElement must be dxWindow)")
		return
	end

	local px,py = getElementData(getElementParent(dxElement),"width"),getElementData(getElementParent(dxElement),"height")
	if relative then
		setElementData(dxElement,"Title:x",x*px)
		setElementData(dxElement,"Title:y",y*py)
	else
		setElementData(dxElement,"Title:x",x)
		setElementData(dxElement,"Title:y",y)
	end
	triggerEvent("onClientDXPropertyChanged",dxElement,"titleposition",x,y,relative)
end

function dxGetPosition(dxElement,relative)
	if not dxElement then
		outputDebugString("dxGetPosition gets wrong parameters (dxElement[,relative=false]")
		return
	end
	local x,y = getElementData(dxElement,"x"),getElementData(dxElement,"y")
	local tx,ty = getElementData(dxElement,"Title:x"),getElementData(dxElement,"Title:y")
	local px,py = getElementData(getElementParent(dxElement),"width"),getElementData(getElementParent(dxElement),"height")
	if tx and ty then
		if relative then
			return x/px,y/py,tx/px,ty/py
		else
			return x,y,tx,ty
		end
	else
		if relative then
			return x/px,y/py
		else
			return x,y
		end
	end
end

function dxGetSize(dxElement,relative)
	if not dxElement then
		outputDebugString("dxGetSize gets wrong parameters (dxElement[,relative=false]")
		return
	end
	local w,h = getElementData(dxElement,"width"),getElementData(dxElement,"height")
	local px,py = getElementData(getElementParent(dxElement),"width"),getElementData(getElementParent(dxElement),"height")
	if relative then
		return w/px,h/py
	else
		return w,h
	end
end

function dxWindowGetMovable(dxWindow)
	if not dxWindow  then
		outputDebugString("dxGetMovable gets wrong parameters (dxWindow)")
		return
	end
	if (getElementType(dxWindow) ~= "dxWindow") then
		outputDebugString("dxWindowSetMovable gets wrong parameters (dxElement must be dxWindow)")
		return
	end
	return getElementData(dxWindow,"movable")
end

function dxWindowIsMoving(dxWindow)
	if not dxWindow  then
		outputDebugString("dxIsMoving gets wrong parameters (dxWindow)")
		return
	end
	if (getElementType(dxWindow) ~= "dxWindow") then
		outputDebugString("dxWindowSetMovable gets wrong parameters (dxElement must be dxWindow)")
		return
	end
	return getElementData(dxWindow,"isMoving")
end

function dxGetVisible(dxElement)
	if not dxElement  then
		outputDebugString("dxGetVisible gets wrong parameters (dxElement)")
		return
	end
	return getElementData(dxElement,"visible")
end

function dxGetElementTheme(dxElement)
	if not dxElement  then
		outputDebugString("dxGetElementTheme gets wrong parameters (dxElement)")
		return
	end
	return getElementData(dxElement,"theme")
end

function dxGetFont(dxElement)
	if not dxElement  then
		outputDebugString("dxGetFont gets wrong parameters (dxElement)")
		return
	end
	return getElementData(dxElement,"font")
end

function dxGetColor(dxElement)
	if not dxElement  then
		outputDebugString("dxGetColor gets wrong parameters (dxElement)")
		return
	end
	local hex = tostring(toHex(getElementData(dxElement,"color")))
	hex = hex:gsub("(..)(......)","%2%1")
	local r,g,b,a = getColorFromString("#"..hex)
	return r,g,b,a
end

function dxGetColorCoded(dxElement)
	if not dxElement  then
		outputDebugString("dxGetColorCoded gets wrong parameters (dxElement)")
		return
	end
	return getElementData(dxElement,"colorcoded")
end

function dxGetText(dxElement)
	if not dxElement  then
		outputDebugString("dxGetText gets wrong parameters (dxElement)")
		return
	end
	return getElementData(dxElement,"text")
end

function dxGetAlpha(dxElement)
	if not dxElement  then
		outputDebugString("dxGetAlpha gets wrong parameters (dxElement)")
		return
	end
	local hex = tostring(toHex(getElementData(dxElement,"color")))
	hex = hex:gsub("(..)(......)","%2%1")
	local r,g,b,a = getColorFromString("#"..hex)
	return a
end

function dxSetPosition(dxElement,x,y,relative,setTitle)
	if not dxElement or not x or not y then
		outputDebugString("dxSetPosition gets wrong parameters (dxElement,x,y[,relative=false,setTitle=true]")
		return
	end
	if relative == nil then
		relative = false
	end
	if setTitle == nil then
		setTitle = true
	end
	local dxType = getElementType(dxElement)
	local px,py = getElementData(getElementParent(dxElement),"width"),getElementData(getElementParent(dxElement),"height")
	if (dxType == "dxWindow") and (setTitle) then
		if relative then
			setElementData(dxElement,"x",x*px)
			setElementData(dxElement,"y",y*py)
			setElementData(dxElement,"Title:x",x*px)
			setElementData(dxElement,"Title:y",y*py)
		else
			setElementData(dxElement,"x",x)
			setElementData(dxElement,"y",y)
			setElementData(dxElement,"Title:x",x)
			setElementData(dxElement,"Title:y",y)
		end
		triggerEvent("onClientDXPropertyChanged",dxElement,"position",x,y,relative,px,py)
	else
		if relative then
			setElementData(dxElement,"x",x*px)
			setElementData(dxElement,"y",y*py)
		else
			setElementData(dxElement,"x",x)
			setElementData(dxElement,"y",y)
		end
		triggerEvent("onClientDXPropertyChanged",dxElement,"position",x,y,relative)
	end
end

function dxSetSize(dxElement,w,h,relative)
	if not dxElement or not w or not h then
		outputDebugString("dxSetSize gets wrong parameters (dxElement,width,height[,relative=false]")
		return
	end
	
	local px,py = getElementData(getElementParent(dxElement),"width"),getElementData(getElementParent(dxElement),"height")
	if relative then
		setElementData(dxElement,"width",w*px)
		setElementData(dxElement,"height",h*py)
	else
		setElementData(dxElement,"width",w)
		setElementData(dxElement,"height",h)
	end
	triggerEvent("onClientDXPropertyChanged",dxElement,"size",w,h,relative)
end

function dxWindowSetMovable(dxWindow,movable)
	if not dxWindow or movable == nil then
		outputDebugString("dxWindowSetMovable gets wrong parameters (dxWindow,movable)")
		return
	end
	if (getElementType(dxWindow) ~= "dxWindow") then
		outputDebugString("dxWindowSetMovable gets wrong parameters (dxElement must be dxWindow)")
		return
	end
	setElementData(dxWindow,"movable",movable)
	triggerEvent("onClientDXPropertyChanged",dxElement,"movable",movable)
end

function dxSetVisible(dxElement,visible)
	if not dxElement or visible == nil  then
		outputDebugString("dxSetVisible gets wrong parameters (dxElement,visible)")
		return
	end
	setElementData(dxElement,"visible",visible)
	triggerEvent("onClientDXPropertyChanged",dxElement,"visible",visible)
end

function dxWindowSetTitleVisible(dxElement,visible)
	if not dxElement or visible == nil  then
		outputDebugString("dxWindowSetTitleVisible gets wrong parameters (dxElement,visible)")
		return
	end
	setElementData(dxElement,"Title:visible",visible)
	triggerEvent("onClientDXPropertyChanged",dxElement,"titlevisible",visible)
end

function dxWindowGetTitleVisible(dxElement)
	if not dxElement then
		outputDebugString("dxWindowGetTitleVisible gets wrong parameters (dxElement)")
		return
	end
	return getElementData(dxElement,"Title:visible")
end

function dxSetElementTheme(dxElement,theme)
	if not dxElement or not theme  then
		outputDebugString("dxSetElementTheme gets wrong parameters (dxElement,theme)")
		return
	end
	setElementData(dxElement,"theme",theme)
	triggerEvent("onClientDXPropertyChanged",dxElement,"theme",theme)
end

function dxSetFont(dxElement,font)
	if not dxElement or not font  then
		outputDebugString("dxSetFont gets wrong parameters (dxElement,font)")
		return
	end
	setElementData(dxElement,"font",font)
	triggerEvent("onClientDXPropertyChanged",dxElement,"font",font)
end

function dxSetColor(dxElement,color)
	if not dxElement or not color  then
		outputDebugString("dxSetFont gets wrong parameters (dxElement,color)")
		return
	end
	setElementData(dxElement,"color",color)
	triggerEvent("onClientDXPropertyChanged",dxElement,"color",color)
end

function dxSetColorCoded(dxElement,colorcoded)
	if not dxElement or colorcoded == nil  then
		outputDebugString("dxSetColorCoded gets wrong parameters (dxElement,colorcoded)")
		return
	end
	setElementData(dxElement,"colorcoded",colorcoded)
	triggerEvent("onClientDXPropertyChanged",dxElement,"colorcoded",colorcoded)
end

function dxSetText(dxElement,text)
	if not dxElement or not text  then
		outputDebugString("dxSetText gets wrong parameters (dxElement,text)")
		return
	end
	setElementData(dxElement,"text",text)
	triggerEvent("onClientDXPropertyChanged",dxElement,"text",text)
end

function dxSetAlpha(dxElement,alpha)
	if not dxElement or not alpha then
		outputDebugString("dxSetAlpha gets wrong parameters (dxElement,alpha)")
		return
	end
	local hex = tostring(toHex(getElementData(dxElement,"color")))
	hex = hex:gsub("(..)(......)","%2%1")
	local r,g,b,a = getColorFromString("#"..hex)
	setElementData(dxElement,"color",tocolor(r,g,b,alpha))
	triggerEvent("onClientDXPropertyChanged",dxElement,"alpha",alpha)
end

function dxMove(dxElement,xMove,yMove,titleMove)
	if not dxElement or not xMove or not yMove then
		outputDebugString("dxMove gets wrong parameters (dxElement,xMove,yMove[,titleMove=true])")
		return
	end

	if titleMove == nil then
		titleMove = true
	end
	local x,y,tx,ty = dxGetPosition(dxElement)
	move = function()
		local movex,movey,movetx,movety = false,false,false,false
		local xx,yy,txx,tyy = dxGetPosition(dxElement)
		if ( xx ~= x+xMove ) then
			if (xx > x+xMove ) then
				xx = xx - 1
			else
				xx = xx + 1
			end
		else
			movex = true
		end
		
		if (yy ~= y+yMove) then
			if (yy > y+yMove) then
				yy = yy -1
			else
				yy = yy +1
			end
		else
			movey = true
		end
		
		if (tx) then
			if ( txx ~= tx+xMove ) then
				if (txx > tx+xMove ) then
					txx = txx - 1
				else
					txx = txx + 1
				end
			else
				movetx = true
			end
		else
			movetx = true
		end
		
		if (ty) then
			if ( tyy ~= ty+yMove ) then
				if (tyy > ty+yMove ) then
					tyy = tyy - 1
				else
					tyy = tyy + 1
				end
			else
				movety = true
			end
		else
			movety = true
		end
		
		if movex and movey and movetx and movety then
			removeEventHandler('onClientRender',getRootElement(),move)
		end
	end
	addEventHandler('onClientRender',getRootElement(),move)
end

function dxCheckBoxGetSelected(dxElement)
	if not dxElement then
		outputDebugString("dxCheckBoxGetSelected gets wrong parameters (dxCheckBox)")
		return
	end
	if (getElementType(dxElement)) ~= "dxCheckBox" then
		outputDebugString("dxCheckBoxGetSelected gets wrong parameters (dxElement must be dxCheckBox)")
		return false
	end
	return getElementData(dxElement,"selected")
end

function dxCheckBoxSetSelected(dxElement,selected)
	if not dxElement or selected == nil then
		outputDebugString("dxCheckBoxSetSelected gets wrong parameters (dxCheckBox)")
		return
	end
	if (getElementType(dxElement)) ~= "dxCheckBox" then
		outputDebugString("dxCheckBoxSetSelected gets wrong parameters (dxElement must be dxCheckBox)")
		return
	end
	setElementData(dxElement,"selected",selected)
	triggerEvent("onClientDXPropertyChanged",dxElement,"selected",selected)
end

function dxRadioButtonGetGroup(dxElement)
	if not dxElement then
		outputDebugString("dxRadioButtonGetGroup gets wrong parameters (dxRadioButton)")
		return
	end
	if (getElementType(dxElement)) ~= "dxRadioButton" then
		outputDebugString("dxRadioButtonGetGroup gets wrong parameters (dxElement must be dxRadioButton)")
		return false
	end
	return getElementData(dxElement,"group")
end

function dxRadioButtonSetGroup(dxElement,groupName)
	if not dxElement or not groupName then
		outputDebugString("dxRadioButtonSetGroup gets wrong parameters (dxRadioButton,groupName)")
		return
	end
	if (getElementType(dxElement)) ~= "dxRadioButton" then
		outputDebugString("dxRadioButtonSetGroup gets wrong parameters (dxElement must be dxRadioButton)")
		return false
	end
	setElementData(dxElement,"group",groupName)
	triggerEvent("onClientDXPropertyChanged",dxElement,"group",group)
end

function dxRadioButtonGetSelected(dxElement)
	if not dxElement then
		outputDebugString("dxRadioButtonGetSelected gets wrong parameters (dxRadioButton)")
		return
	end
	if (getElementType(dxElement)) ~= "dxRadioButton" then
		outputDebugString("dxRadioButtonGetSelected gets wrong parameters (dxElement must be dxRadioButton)")
		return false
	end
	return getElementData(dxElement,"selected")
end

function dxRadioButtonSetSelected(dxElement,selected)
	if not dxElement or selected == nil then
		outputDebugString("dxRadioButtonSetSelected gets wrong parameters (dxRadioButton)")
		return
	end
	if (getElementType(dxElement)) ~= "dxRadioButton" then
		outputDebugString("dxRadioButtonSetSelected gets wrong parameters (dxElement must be dxRadioButton)")
		return
	end

	if selected then
		for _,element in ipairs(getElementChildren(getElementParent(dxElement))) do
			if (getElementType(element)=="dxRadioButton" and dxRadioButtonGetGroup(element) == dxRadioButtonGetGroup(dxElement)) then
				setElementData(element,"selected",false)
			end
		end
	end
	setElementData(dxElement,"selected",selected)
	triggerEvent("onClientDXPropertyChanged",dxElement,"selected",selected)
end

function dxLabelGetScale(dxElement) 
	if not dxElement then
		outputDebugString("dxLabelGetScale gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxLabel") then
		outputDebugString("dxLabelGetScale gets wrong parameters.(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"scale")
end

function dxLabelGetHorizontalAlign(dxElement) 
	if not dxElement then
		outputDebugString("dxLabelGetHorizontalAlign gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxLabel") then
		outputDebugString("dxLabelGetHorizontalAlign gets wrong parameters.(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"alignX")
end

function dxLabelGetVerticalAlign(dxElement) 
	if not dxElement then
		outputDebugString("dxLabelGetVerticalAlign gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxLabel") then
		outputDebugString("dxLabelGetVerticalAlign gets wrong parameters.(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"alignY")
end

function dxLabelSetScale(dxElement,scale) 
	if not dxElement or not scale then
		outputDebugString("dxLabelGetScale gets wrong parameters.(dxElement,scale)")
		return
	end
	if (getElementType(dxElement)~="dxLabel") then
		outputDebugString("dxLabelGetScale gets wrong parameters.(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"scale",scale)
	triggerEvent("onClientDXPropertyChanged",dxElement,"scale",scale)
end

function dxLabelSetHorizontalAlign(dxElement,alignX) 
	if not dxElement or not alignX then
		outputDebugString("dxLabelGetHorizontalAlign gets wrong parameters.(dxElement,alignX)")
		return
	end
	if (getElementType(dxElement)~="dxLabel") then
		outputDebugString("dxLabelGetHorizontalAlign gets wrong parameters.(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"alignX",alignX)
	triggerEvent("onClientDXPropertyChanged",dxElement,"alignX",alignX)
end

function dxLabelSetVerticalAlign(dxElement,alignY) 
	if not dxElement or not alignY then
		outputDebugString("dxLabelGetVerticalAlign gets wrong parameters.(dxElement,alignY)")
		return
	end
	if (getElementType(dxElement)~="dxLabel") then
		outputDebugString("dxLabelGetVerticalAlign gets wrong parameters.(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"alignY",alignY)
	triggerEvent("onClientDXPropertyChanged",dxElement,"alignY",alignY)
end

function dxStaticImageGetLoadedImage(dxElement)
	if not dxElement then
		outputDebugString("dxStaticImageGetLoadedImage gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxStaticImage") then
		outputDebugString("dxStaticImageGetLoadedImage gets wrong parameters.(dxElement must be dxStaticImage)")
		return
	end
	return getElementData(dxElement,"image")
end

function dxStaticImageLoadImage(dxElement,path)
	if not dxElement or not path then
		outputDebugString("dxStaticImageLoadImage gets wrong parameters.(dxElement,path)")
		return
	end
	if (getElementType(dxElement)~="dxStaticImage") then
		outputDebugString("dxStaticImageLoadImage gets wrong parameters.(dxElement must be dxStaticImage)")
		return
	end
	if not fileExists(path) then
		return false
	end
	setElementData(dxElement,"image",path)
	triggerEvent("onClientDXPropertyChanged",dxElement,"image",path)
	return true
end

function dxStaticImageGetSection(dxElement)
	if not dxElement then
		outputDebugString("dxStaticImageGetSection gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxStaticImage") then
		outputDebugString("dxStaticImageGetSection gets wrong parameters.(dxElement must be dxStaticImage)")
		return
	end
	if not (getElementData(dxElement,"Section")) then
		return false
	end
	return getElementData(dxElement,"Section:x"),getElementData(dxElement,"Section:y"),
		getElementData(dxElement,"Section:width"),getElementData(dxElement,"Section:height")
end

function dxStaticImageSetSection(dxElement,sectionX,sectionY,sectionW,sectionH)
	if not dxElement then
		outputDebugString("dxStaticImageSetSection gets wrong parameters.(dxElement,[(sectionX,sectionY,sectionW,sectionH=false)])")
		return
	end
	if (getElementType(dxElement)~="dxStaticImage") then
		outputDebugString("dxStaticImageSetSection gets wrong parameters.(dxElement must be dxStaticImage)")
		return
	end
	if not sectionX then
		setElementData(dxElement,"Section",false)
		setElementData(dxElement,"Section:x",false)
		setElementData(dxElement,"Section:y",false)
		setElementData(dxElement,"Section:width",false)
		setElementData(dxElement,"Section:height",false)
		triggerEvent("onClientDXPropertyChanged",dxElement,"section",false)
		return true
	end
	setElementData(dxElement,"Section",true)
	setElementData(dxElement,"Section:x",sectionX)
	setElementData(dxElement,"Section:y",sectionY)
	setElementData(dxElement,"Section:width",sectionW)
	setElementData(dxElement,"Section:height",sectionH)
	triggerEvent("onClientDXPropertyChanged",dxElement,"section",true,sectionX,sectionY,sectionW,sectionH)
	return true
end

function dxStaticImageGetRotation(dxElement)
	if not dxElement then
		outputDebugString("dxStaticImageGetRotation gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxStaticImage") then
		outputDebugString("dxStaticImageGetRotation gets wrong parameters.(dxElement must be dxStaticImage)")
		return
	end
	return getElementData(dxElement,"rotation")
end

function dxStaticImageSetRotation(dxElement,rot)
	if not dxElement or not rot then
		outputDebugString("dxStaticImageSetRotation gets wrong parameters.(dxElement,path)")
		return
	end
	if (getElementType(dxElement)~="dxStaticImage") then
		outputDebugString("dxStaticImageSetRotation gets wrong parameters.(dxElement must be dxStaticImage)")
		return
	end
	setElementData(dxElement,"rotation",rot)
	triggerEvent("onClientDXPropertyChanged",dxElement,"rotation",rot)
end

function dxProgressBarGetProgress(dxElement)
	if not dxElement then
		outputDebugString("dxProgressBarGetProgress gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarGetProgress gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	return getElementData(dxElement,"progress")
end

function dxProgressBarSetProgress(dxElement,progress)
	if not dxElement or not progress then
		outputDebugString("dxProgressBarSetProgress gets wrong parameters.(dxElement,progress)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarSetProgress gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	local max = getElementData(dxElement,"max")
	if type(progress)~="number" or progress < 0 or progress > max then
		outputDebugString("dxProgressBarSetProgress gets wrong parameters.(progress must be between 0-"..tostring(max))
		return
	end
	setElementData(dxElement,"progress",progress)
	triggerEvent("onClientDXPropertyChanged",dxElement,"progress",progress)
end

function dxProgressBarGetProgressPercent(dxElement)
	if not dxElement then
		outputDebugString("dxProgressBarGetProgressPercent gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarGetProgressPercent gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	-- max progress
	-- 100 x
	return (100*getElementData(dxElement,"progress")) / getElementData(dxElement,"max")
end

function dxProgressBarSetProgressPercent(dxElement,progress)
	if not dxElement or not progress then
		outputDebugString("dxProgressBarSetProgressPercent gets wrong parameters.(dxElement,percent)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarSetProgressPercent gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	if type(progress)~="number" or progress < 0 or progress > 100 then
		outputDebugString("dxProgressBarSetProgressPercent gets wrong parameters.(percent must be between 0-100)")
		return
	end
	-- 100 percent
	-- max x
	setElementData(dxElement,"progress",(getElementData(dxElement,"max")*progress)/100)
	triggerEvent("onClientDXPropertyChanged",dxElement,"progressPercent",progress,(getElementData(dxElement,"max")*progress)/100)
end

function dxProgressBarGetMaxProgress(dxElement)
	if not dxElement then
		outputDebugString("dxProgressBarGetMaxProgress gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarGetMaxProgress gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	return getElementData(dxElement,"max")
end

function dxProgressBarSetMaxProgress(dxElement,progress)
	if not dxElement or not progress then
		outputDebugString("dxProgressBarSetMaxProgress gets wrong parameters.(dxElement,maxProgress)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarSetMaxProgress gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	setElementData(dxElement,"max",progress)
	triggerEvent("onClientDXPropertyChanged",dxElement,"maxProgress",progress)
	if (getElementData(dxElement,"progress") > progress ) then
		dxProgressBarSetProgress(dxElement,progress)
	end
end

function dxScrollBarGetScroll(dxElement)
	if not dxElement then
		outputDebugString("dxScrollBarGetScroll gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxScrollBar") then
		outputDebugString("dxScrollBarGetScroll gets wrong parameters.(dxElement must be dxScrollBar)")
		return
	end
	return getElementData(dxElement,"progress")
end

function dxScrollBarSetScroll(dxElement,progress)
	if not dxElement or not progress then
		outputDebugString("dxScrollBarSetScroll gets wrong parameters.(dxElement,progress)")
		return
	end
	if (getElementType(dxElement)~="dxScrollBar") then
		outputDebugString("dxScrollBarSetScroll gets wrong parameters.(dxElement must be dxScrollBar)")
		return
	end
	local max = getElementData(dxElement,"max")
	if type(progress)~="number" or progress < 0 or progress > max then
		outputDebugString("dxScrollBarSetScroll gets wrong parameters.(progress must be between 0-"..tostring(max))
		return
	end
	setElementData(dxElement,"progress",progress)
	triggerEvent("onClientDXPropertyChanged",dxElement,"scroll",progress)
	triggerEvent("onClientDXScroll",dxElement,progress)
end

function dxScrollBarGetScrollPercent(dxElement)
	if not dxElement then
		outputDebugString("dxScrollBarGetScrollPercent gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxScrollBar") then
		outputDebugString("dxScrollBarGetScrollPercent gets wrong parameters.(dxElement must be dxScrollBar)")
		return
	end
	-- max progress
	-- 100 x
	return (100*getElementData(dxElement,"progress")) / getElementData(dxElement,"max")
end

function dxScrollBarSetScrollPercent(dxElement,progress)
	if not dxElement or not progress then
		outputDebugString("dxScrollBarSetScrollPercent gets wrong parameters.(dxElement,percent)")
		return
	end
	if (getElementType(dxElement)~="dxScrollBar") then
		outputDebugString("dxScrollBarSetScrollPercent gets wrong parameters.(dxElement must be dxScrollBar)")
		return
	end
	if type(progress)~="number" or progress < 0 or progress > 100 then
		outputDebugString("dxScrollBarSetScrollPercent gets wrong parameters.(percent must be between 0-100)")
		return
	end
	-- 100 percent
	-- max x
	setElementData(dxElement,"progress",(getElementData(dxElement,"max")*progress)/100)
	triggerEvent("onClientDXPropertyChanged",dxElement,"scrollPercent",progress,(getElementData(dxElement,"max")*progress)/100)
	triggerEvent("onClientDXScroll",dxElement,(getElementData(dxElement,"max")*progress)/100)
end

function dxScrollBarGetMaxScroll(dxElement)
	if not dxElement then
		outputDebugString("dxScrollBarGetMaxScroll gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxScrollBar") then
		outputDebugString("dxScrollBarGetMaxScroll gets wrong parameters.(dxElement must be dxScrollBar)")
		return
	end
	return getElementData(dxElement,"max")
end

function dxScrollBarSetMaxScroll(dxElement,progress)
	if not dxElement or not progress then
		outputDebugString("dxScrollBarSetMaxScroll gets wrong parameters.(dxElement,maxProgress)")
		return
	end
	if (getElementType(dxElement)~="dxScrollBar") then
		outputDebugString("dxScrollBarSetMaxScroll gets wrong parameters.(dxElement must be dxScrollBar)")
		return
	end
	setElementData(dxElement,"max",progress)
	triggerEvent("onClientDXPropertyChanged",dxElement,"maxScroll",progress)
	if (getElementData(dxElement,"progress") > progress ) then
		dxScrollBarSetProgress(dxElement,progress)
	end
end

function dxSpinnerGetPosition(dxElement)
	if not dxElement then
		outputDebugString("dxSpinnerGetPosition gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxSpinner") then
		outputDebugString("dxSpinnerGetPosition gets wrong parameters.(dxElement must be dxSpinner)")
		return
	end
	return getElementData(dxElement,"position")
end

function dxSpinnerSetPosition(dxElement,pos)
	if not dxElement or not pos then
		outputDebugString("dxSpinnerSetMax gets wrong parameters.(dxElement,pos)")
		return
	end
	if (getElementType(dxElement)~="dxSpinner") then
		outputDebugString("dxSpinnerSetMax gets wrong parameters.(dxElement must be dxSpinner)")
		return
	end
	if (pos <= getElementData(dxElement,"max") and pos >= getElementData(dxElement,"min")) then
		setElementData(dxElement,"position",pos)
		triggerEvent("onClientDXSpin",dxElement,pos)
		return true
	end
	return false
end

function dxSpinnerGetMax(dxElement)
	if not dxElement then
		outputDebugString("dxSpinnerGetMax gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxSpinner") then
		outputDebugString("dxSpinnerGetMax gets wrong parameters.(dxElement must be dxSpinner)")
		return
	end
	return getElementData(dxElement,"max")
end

function dxSpinnerSetMax(dxElement,max_)
	if not dxElement or not max_ then
		outputDebugString("dxSpinnerSetMax gets wrong parameters.(dxElement,max)")
		return
	end
	if (getElementType(dxElement)~="dxSpinner") then
		outputDebugString("dxSpinnerSetMax gets wrong parameters.(dxElement must be dxSpinner)")
		return
	end
	setElementData(dxElement,"max",max_)
	if ( dxSpinnerGetPosition(dxElement) > max_ ) then
		dxSpinnerSetPosition(dxElement,max_)
	end
	return true
end

function dxSpinnerGetMin(dxElement)
	if not dxElement then
		outputDebugString("dxSpinnerGetMin gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxSpinner") then
		outputDebugString("dxSpinnerGetMin gets wrong parameters.(dxElement must be dxSpinner)")
		return
	end
	return getElementData(dxElement,"min")
end

function dxSpinnerSetMin(dxElement,min_)
	if not dxElement or not min_ then
		outputDebugString("dxSpinnerSetMin gets wrong parameters.(dxElement,min)")
		return
	end
	if (getElementType(dxElement)~="dxSpinner") then
		outputDebugString("dxSpinnerSetMin gets wrong parameters.(dxElement must be dxSpinner)")
		return
	end
	setElementData(dxElement,"min",min_)
	if ( dxSpinnerGetPosition(dxElement) < min_ ) then
		dxSpinnerSetPosition(dxElement,min_)
	end
	return true
end

function dxRefreshStates(container)
	if not container then
		container = dxGetRootPane()
	end
	
	local absoluteX,absoluteY = getCursorAbsolute()
	local containerVisible = false
	if (dxGetVisible(container)) then
		if ( getElementType(container) ~= "dxRootPane") then
			if (getElementData(getElementParent(container),"visible")) then
				containerVisible = true
			else
				containerVisible = false
			end
		else
			containerVisible = true
		end
	end
	if containerVisible then
		for _,element in ipairs(getElementChildren(container)) do 
			if ( dxGetVisible(element) ) then
				if (getElementData(element,"container")) then
					dxRefreshStates(element)
				else
					local x = getElementData(container,"x")+getElementData(element,"x")
					local y = getElementData(container,"y")+getElementData(element,"y")
					local width = getElementData(element,"width")
					local height = getElementData(element,"height")
					if ( getElementType(container) == "dxWindow" ) then
						y = y+getElementData(getElementData(getElementParent(element),"theme"),"TitleBarTopLeft:Height")-1
					end
					if (isCursorShowing()) then
						local hover = getElementData(element,"hover")
						local push = getElementData(element,"push")
						setElementData(element,"hover",false)
						setElementData(element,"push",false)
						if ( intersect(x,y,x+width,y+height,absoluteX,absoluteY) ) then
							if (getKeyState("mouse1")) and getElementData(element,"clicked") then
								setElementData(element,"push",true)
								setElementData(element,"hover",true)
							else
								setElementData(element,"hover",true)
							end
						end
						local push1 = getElementData(element,"push")
						local hover1 = getElementData(element,"hover")
						if (not hover) and (hover1) then
							triggerEvent("onClientDXMouseEnter",element,absoluteX,absoluteY)
						end
						
						if hover and (not hover1) then
							triggerEvent("onClientDXMouseLeave",element,absoluteX,absoluteY)
						end
					end
				end
			end
		end
	end
end

addEventHandler("onClientRender",getRootElement(),
	function()
		dxRefreshStates()
		for _,element in ipairs(getElementsByType("dxScrollBar")) do
			if (getElementData(element,"GiveUp")) then
				local scroll = dxScrollBarGetScroll(element)
				if scroll >0 then
					dxScrollBarSetScroll(element,scroll-1)
				end
			end
			
			if (getElementData(element,"GiveDown")) then
				local scroll = dxScrollBarGetScroll(element)
				if scroll < dxScrollBarGetMaxScroll(element) then
					dxScrollBarSetScroll(element,scroll+1)
				end
			end
			
			if ( getElementData(element,"isMoving") ) then
				if (getElementData(element,"type") == "Vertical") then
					local cTheme = dxGetElementTheme(element)
					local absoluteX,absoluteY = getCursorAbsolute()
					local upArrowH=getElementData(cTheme,"ScrollUpArrow:Height")
					local downArrowH=getElementData(cTheme,"ScrollDownArrow:Height")
					local thumb = getElementData(cTheme,"ScrollbarThumb:Height")
					local _,ry = dxGetPosition(element)
					ry = ry + getElementData(getElementParent(element),"y")
					local ay = absoluteY-ry-upArrowH-downArrowH-(thumb/2)+2
					-- %100'da h ise
					-- y'de	ay'dır
					local y50 = ((ay*100) / getElementData(element,"height"))
					dxScrollBarSetScrollPercent(element,y50)
				else
					local cTheme = dxGetElementTheme(element)
					local upArrowW=getElementData(cTheme,"ScrollLeftArrow:Width")
					local downArrowW=getElementData(cTheme,"ScrollRightArrow:Width")
					local thumb = getElementData(cTheme,"ScrollbarThumb:Width")
					local absoluteX,absoluteY = getCursorAbsolute()
					local rx,_ = dxGetPosition(element)
					rx = rx + getElementData(getElementParent(element),"x")
					local ax = absoluteX-rx-upArrowW-(thumb/2)
					-- %100'da w ise
					-- y'de	ax'dır
					local y50 = ((ax*100) / getElementData(element,"width"))
					dxScrollBarSetScrollPercent(element,y50)
				end
			end
		end
		
		for _,element in ipairs(getElementsByType("dxSpinner")) do
			if (getElementData(element,"clicked")) then
				if (getElementData(element,"increasing")) then
					dxSpinnerSetPosition(element,dxSpinnerGetPosition(element)+1)
					setElementData(element,"increasing",false)
					setElementData(element,"increasing",false)
					setElementData(element,"increaseRender",true)
					incControl = function(elm)
						if (getElementData(elm,"increaseRender")) then
							setElementData(elm,"increasing",true)
						end
					end
					setTimer(incControl,100,1,element)
				end
				
				if (getElementData(element,"reducing")) then
					dxSpinnerSetPosition(element,dxSpinnerGetPosition(element)-1)
					setElementData(element,"reducing",false)
					setElementData(element,"reduceRender",true)
					reduceControl = function(elm)
						if (getElementData(elm,"reduceRender")) then
							setElementData(elm,"reducing",true)
						end
					end
					setTimer(reduceControl,100,1,element)
				end
			end
		end
		
		for _,element in ipairs(getElementsByType("dxWindow")) do
			if dxGetVisible(element)  and getElementData(getElementParent(element),"visible")  then
				if (isCursorShowing()) and getElementData(element,"movable") and getElementData(element,"isMoving") then
					local x,y = getCursorAbsolute()
					setElementData(element,"Title:x",x-getElementData(element,"Move:x"))
					setElementData(element,"Title:y",y-getElementData(element,"Move:y"))
					setElementData(element,"x",x-getElementData(element,"Move:x"))
					setElementData(element,"y",y-getElementData(element,"Move:y"))
				end
			end
			if dxGetVisible(element) and getElementData(getElementParent(element),"visible") then
				
				local x,y,w,h = getElementData(element,"x"),getElementData(element,"y"),
								getElementData(element,"width"),getElementData(element,"height")
				local titlex,titley = getElementData(element,"Title:x"),getElementData(element,"Title:y")
				local title,color = getElementData(element,"text"),getElementData(element,"color")
				local theme,font = getElementData(element,"theme"),getElementData(element,"font")
				
				if getElementData(element,"clicked") then
					-- Drawing title bar
					if (getElementData(element,"Title:visible")) then
						dxDrawImageSection(titlex,titley,
							getElementData(theme,"TitleBarTopLeftSelected:Width"),getElementData(theme,"TitleBarTopLeftSelected:Height"),
							getElementData(theme,"TitleBarTopLeftSelected:X"),getElementData(theme,"TitleBarTopLeftSelected:Y"),
							getElementData(theme,"TitleBarTopLeftSelected:Width"),getElementData(theme,"TitleBarTopLeftSelected:Height"),
							getElementData(theme,"TitleBarTopLeftSelected:images"),0,0,0,color,false)
							
						dxDrawImageSection(titlex+getElementData(theme,"TitleBarTopLeftSelected:Width"),titley,
							w-getElementData(theme,"TitleBarTopLeftSelected:Width")-getElementData(theme,"TitleBarTopRightSelected:Width"),
							getElementData(theme,"TitleBarTopLeftSelected:Height"),
							getElementData(theme,"TitleBarBackgroundSelected:X"),getElementData(theme,"TitleBarBackgroundSelected:Y"),
							getElementData(theme,"TitleBarBackgroundSelected:Width"),getElementData(theme,"TitleBarBackgroundSelected:Height"),
							getElementData(theme,"TitleBarBackgroundSelected:images"),0,0,0,color,false)
						
						dxDrawImageSection(titlex+w-getElementData(theme,"TitleBarTopRightSelected:Width"),titley,
							getElementData(theme,"TitleBarTopRightSelected:Width"),getElementData(theme,"TitleBarTopRightSelected:Height"),
							getElementData(theme,"TitleBarTopRightSelected:X"),getElementData(theme,"TitleBarTopRightSelected:Y"),
							getElementData(theme,"TitleBarTopRightSelected:Width"),getElementData(theme,"TitleBarTopRightSelected:Height"),
							getElementData(theme,"TitleBarTopRightSelected:images"),0,0,0,color,false)
						local tw = w-getElementData(theme,"TitleBarTopLeftSelected:Width")-getElementData(theme,"TitleBarTopRightSelected:Width")
						local tx = titlex+getElementData(theme,"TitleBarTopLeftSelected:Width")
						local th = getElementData(theme,"TitleBarTopRightSelected:Height")
						local textWidth = dxGetTextWidth(title,1,font)
						if (dxGetColorCoded(element)) then
							textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
						else
							textWidth = dxGetTextWidth(title,1,font)
						end
						if textWidth > tw-50 then
							while textWidth>tw-50 do
								title = title:sub(1,title:len()-6).."..."
								if (dxGetColorCoded(element)) then
									textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
								else
									textWidth = dxGetTextWidth(title,1,font)
								end
							end
						end
						local textHeight = dxGetFontHeight(1,font)
						local textX = titlex+((tw-textWidth)/2)+getElementData(theme,"TitleBarTopLeftSelected:Width")
						local textY = titley+((th-textHeight)/2)
						if (dxGetColorCoded(element)) then
							dxDrawColorText(title,textX,textY,textX,textY,color,1,font)
						else
							dxDrawText(title,textX,textY,textX,textY,color,1,font)
						end
					end
					local hex = tostring(toHex(color))
					hex = hex:gsub("(..)(......)","%2%1")
					local r,g,b,a = getColorFromString("#"..hex)
					if (a > 20) then
						a = a-20
					end
					-- Drawing component pane
					local leftw = getElementData(theme,"Frame2Left:Width")
					local rightw = getElementData(theme,"Frame2Right:Width")
					dxDrawImageSection(x+leftw,y+getElementData(theme,"TitleBarTopLeft:Height")-1,w-leftw-rightw,getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Top:X"),getElementData(theme,"Frame2Top:Y"),
							getElementData(theme,"Frame2Top:Width"),getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Top:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x,y+getElementData(theme,"TitleBarTopLeft:Height")-1,leftw,h+getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Left:X"),getElementData(theme,"Frame2Left:Y"),
							getElementData(theme,"Frame2Left:Width"),getElementData(theme,"Frame2Left:Height"),
							getElementData(theme,"Frame2Left:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+leftw,y+getElementData(theme,"TitleBarTopLeft:Height")-1+getElementData(theme,"Frame2Top:Height"),w-leftw-rightw,h,
							getElementData(theme,"Frame2Background:X"),getElementData(theme,"Frame2Background:Y"),
							getElementData(theme,"Frame2Background:Width"),getElementData(theme,"Frame2Background:Height"),
							getElementData(theme,"Frame2Background:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+(w-leftw),y+getElementData(theme,"TitleBarTopLeft:Height")-1,rightw,h+getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Right:X"),getElementData(theme,"Frame2Right:Y"),
							getElementData(theme,"Frame2Right:Width"),getElementData(theme,"Frame2Right:Height"),
							getElementData(theme,"Frame2Right:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x,y+getElementData(theme,"TitleBarTopLeft:Height")-1+h+getElementData(theme,"Frame2Top:Height"),getElementData(theme,"Frame2BottomLeft:Width"),getElementData(theme,"Frame2BottomLeft:Height"),
							getElementData(theme,"Frame2BottomLeft:X"),getElementData(theme,"Frame2BottomLeft:Y"),
							getElementData(theme,"Frame2BottomLeft:Width"),getElementData(theme,"Frame2BottomLeft:Height"),
							getElementData(theme,"Frame2BottomLeft:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+getElementData(theme,"Frame2BottomLeft:Width"),y+getElementData(theme,"Frame2Top:Height")+getElementData(theme,"TitleBarTopLeft:Height")-1+h,w-getElementData(theme,"Frame2BottomLeft:Width")-getElementData(theme,"Frame2BottomRight:Width"),getElementData(theme,"Frame2Bottom:Height"),
							getElementData(theme,"Frame2Bottom:X"),getElementData(theme,"Frame2Bottom:Y"),
							getElementData(theme,"Frame2Bottom:Width"),getElementData(theme,"Frame2Bottom:Height"),
							getElementData(theme,"Frame2Bottom:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+(w-leftw),y+getElementData(theme,"TitleBarTopLeft:Height")-1+h+getElementData(theme,"Frame2Top:Height"),getElementData(theme,"Frame2BottomRight:Width"),getElementData(theme,"Frame2BottomRight:Height"),
							getElementData(theme,"Frame2BottomRight:X"),getElementData(theme,"Frame2BottomRight:Y"),
							getElementData(theme,"Frame2BottomRight:Width"),getElementData(theme,"Frame2BottomRight:Height"),
							getElementData(theme,"Frame2BottomRight:images"),0,0,0,tocolor(r,g,b,a),false)
				else
					-- Drawing title bar
					if (getElementData(element,"Title:visible")) then
						dxDrawImageSection(titlex,titley,
							getElementData(theme,"TitleBarTopLeft:Width"),getElementData(theme,"TitleBarTopLeft:Height"),
							getElementData(theme,"TitleBarTopLeft:X"),getElementData(theme,"TitleBarTopLeft:Y"),
							getElementData(theme,"TitleBarTopLeft:Width"),getElementData(theme,"TitleBarTopLeft:Height"),
							getElementData(theme,"TitleBarTopLeft:images"),0,0,0,color,false)
							
						dxDrawImageSection(titlex+getElementData(theme,"TitleBarTopLeft:Width"),titley,
							w-getElementData(theme,"TitleBarTopLeft:Width")-getElementData(theme,"TitleBarTopRight:Width"),
							getElementData(theme,"TitleBarTopLeft:Height"),
							getElementData(theme,"TitleBarBackground:X"),getElementData(theme,"TitleBarBackground:Y"),
							getElementData(theme,"TitleBarBackground:Width"),getElementData(theme,"TitleBarBackground:Height"),
							getElementData(theme,"TitleBarBackground:images"),0,0,0,color,false)
						
						dxDrawImageSection(titlex+w-getElementData(theme,"TitleBarTopRight:Width"),titley,
							getElementData(theme,"TitleBarTopRight:Width"),getElementData(theme,"TitleBarTopRight:Height"),
							getElementData(theme,"TitleBarTopRight:X"),getElementData(theme,"TitleBarTopRight:Y"),
							getElementData(theme,"TitleBarTopRight:Width"),getElementData(theme,"TitleBarTopRight:Height"),
							getElementData(theme,"TitleBarTopRight:images"),0,0,0,color,false)
						local tw = w-getElementData(theme,"TitleBarTopLeft:Width")-getElementData(theme,"TitleBarTopRight:Width")
						local tx = titlex+getElementData(theme,"TitleBarTopLeft:Width")
						local th = getElementData(theme,"TitleBarTopRight:Height")
						local textWidth = dxGetTextWidth(title,1,font)
						if (dxGetColorCoded(element)) then
							textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
						else
							textWidth = dxGetTextWidth(title,1,font)
						end
						if textWidth > tw-50 then
							while textWidth>tw-50 do
								title = title:sub(1,title:len()-6).."..."
								if (dxGetColorCoded(element)) then
									textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
								else
									textWidth = dxGetTextWidth(title,1,font)
								end
							end
						end
						local textHeight = dxGetFontHeight(1,font)
						local textX = titlex+((tw-textWidth)/2)+getElementData(theme,"TitleBarTopLeft:Width")
						local textY = titley+((th-textHeight)/2)
						if (dxGetColorCoded(element)) then
							dxDrawColorText(title,textX,textY,textX,textY,color,1,font)
						else
							dxDrawText(title,textX,textY,textX,textY,color,1,font)
						end
					end
				
					local hex = tostring(toHex(color))
					hex = hex:gsub("(..)(......)","%2%1")
					local r,g,b,a = getColorFromString("#"..hex)
					if (a > 20) then
						a = a-20
					end
					-- Drawing component pane
					local leftw = getElementData(theme,"Frame2Left:Width")
					local rightw = getElementData(theme,"Frame2Right:Width")
					dxDrawImageSection(x+leftw,y+getElementData(theme,"TitleBarTopLeft:Height")-1,w-leftw-rightw,getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Top:X"),getElementData(theme,"Frame2Top:Y"),
							getElementData(theme,"Frame2Top:Width"),getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Top:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x,y+getElementData(theme,"TitleBarTopLeft:Height")-1,leftw,h+getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Left:X"),getElementData(theme,"Frame2Left:Y"),
							getElementData(theme,"Frame2Left:Width"),getElementData(theme,"Frame2Left:Height"),
							getElementData(theme,"Frame2Left:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+leftw,y+getElementData(theme,"TitleBarTopLeft:Height")-1+getElementData(theme,"Frame2Top:Height"),w-leftw-rightw,h,
							getElementData(theme,"Frame2Background:X"),getElementData(theme,"Frame2Background:Y"),
							getElementData(theme,"Frame2Background:Width"),getElementData(theme,"Frame2Background:Height"),
							getElementData(theme,"Frame2Background:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+(w-leftw),y+getElementData(theme,"TitleBarTopLeft:Height")-1,rightw,h+getElementData(theme,"Frame2Top:Height"),
							getElementData(theme,"Frame2Right:X"),getElementData(theme,"Frame2Right:Y"),
							getElementData(theme,"Frame2Right:Width"),getElementData(theme,"Frame2Right:Height"),
							getElementData(theme,"Frame2Right:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x,y+getElementData(theme,"TitleBarTopLeft:Height")-1+h+getElementData(theme,"Frame2Top:Height"),getElementData(theme,"Frame2BottomLeft:Width"),getElementData(theme,"Frame2BottomLeft:Height"),
							getElementData(theme,"Frame2BottomLeft:X"),getElementData(theme,"Frame2BottomLeft:Y"),
							getElementData(theme,"Frame2BottomLeft:Width"),getElementData(theme,"Frame2BottomLeft:Height"),
							getElementData(theme,"Frame2BottomLeft:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+getElementData(theme,"Frame2BottomLeft:Width"),y+getElementData(theme,"Frame2Top:Height")+getElementData(theme,"TitleBarTopLeft:Height")-1+h,w-getElementData(theme,"Frame2BottomLeft:Width")-getElementData(theme,"Frame2BottomRight:Width"),getElementData(theme,"Frame2Bottom:Height"),
							getElementData(theme,"Frame2Bottom:X"),getElementData(theme,"Frame2Bottom:Y"),
							getElementData(theme,"Frame2Bottom:Width"),getElementData(theme,"Frame2Bottom:Height"),
							getElementData(theme,"Frame2Bottom:images"),0,0,0,tocolor(r,g,b,a),false)
					dxDrawImageSection(x+(w-leftw),y+getElementData(theme,"TitleBarTopLeft:Height")-1+h+getElementData(theme,"Frame2Top:Height"),getElementData(theme,"Frame2BottomRight:Width"),getElementData(theme,"Frame2BottomRight:Height"),
							getElementData(theme,"Frame2BottomRight:X"),getElementData(theme,"Frame2BottomRight:Y"),
							getElementData(theme,"Frame2BottomRight:Width"),getElementData(theme,"Frame2BottomRight:Height"),
							getElementData(theme,"Frame2BottomRight:images"),0,0,0,tocolor(r,g,b,a),false)
				end
				-- Drawing components
				local cpx = x
				local cpy = y+getElementData(theme,"TitleBarBackground:Height")-1
				for _,aElements in ipairs(attachedElements) do
					if ( aElements[1] == element ) then
						guiSetPosition(aElements[2],cpx+aElements[3],cpy+aElements[4],false)
					end
				end
				for _,component in ipairs(getElementChildren(element)) do
					if dxGetVisible(component) then
						local eType = getElementType(component)
						local cTheme = getElementData(component,"theme")
								or getElementData(getElementParent(component),"theme")
						
						local cx,cy,cw,ch = getElementData(component,"x"),getElementData(component,"y"),
										   getElementData(component,"width"),
										   getElementData(component,"height")
										   
						local color = getElementData(component,"color")
						local font = getElementData(component,"font")
						
						if not font then
							font = "default"
						end
						if not color then
							color = tocolor(255,255,255,255)
						end
						for _,aElements in ipairs(attachedElements) do
							if ( aElements[1] == component ) then
								guiSetPosition(aElements[2],cpx+cx+aElements[3],cpy+cy+aElements[4],false)
							end
						end
						if (eType=="dxButton") then
							local cpxx = cpx+cx
							local cpyy = cpy+cy
							-- Button drawings
							local imageset = "S"
							if ( getElementData(component,"push") ) then
								imageset = "S"
							elseif ( getElementData(component,"hover") ) then
								imageset = ""
							end
							
							local leftw,rightw = getElementData(cTheme,imageset.."ButtonLeft:Width"),getElementData(cTheme,imageset.."ButtonRight:Width")
							local toplefth,botlefth = getElementData(cTheme,imageset.."ButtonTopLeft:Height"),getElementData(cTheme,imageset.."ButtonBottomLeft:Height")
							local toprigth,botright = getElementData(cTheme,imageset.."ButtonTopRight:Height"),getElementData(cTheme,imageset.."ButtonBottomRight:Height")
							local toph,both = getElementData(cTheme,imageset.."ButtonTop:Height"), getElementData(cTheme,imageset.."ButtonBottom:Height")
							dxDrawImageSection(cpxx,cpyy,getElementData(cTheme,imageset.."ButtonTopLeft:Width"),getElementData(cTheme,imageset.."ButtonTopLeft:Height"),
								getElementData(cTheme,imageset.."ButtonTopLeft:X"),getElementData(cTheme,imageset.."ButtonTopLeft:Y"),
								getElementData(cTheme,imageset.."ButtonTopLeft:Width"),getElementData(cTheme,imageset.."ButtonTopLeft:Height"),
								getElementData(cTheme,imageset.."ButtonTopLeft:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx,cpyy+toplefth,getElementData(cTheme,imageset.."ButtonLeft:Width"),ch-toplefth-botlefth,
								getElementData(cTheme,imageset.."ButtonLeft:X"),getElementData(cTheme,imageset.."ButtonLeft:Y"),
								getElementData(cTheme,imageset.."ButtonLeft:Width"),getElementData(cTheme,imageset.."ButtonLeft:Height"),
								getElementData(cTheme,imageset.."ButtonLeft:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx,cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,imageset.."ButtonBottomLeft:Width"),botlefth,
								getElementData(cTheme,imageset.."ButtonBottomLeft:X"),getElementData(cTheme,imageset.."ButtonBottomLeft:Y"),
								getElementData(cTheme,imageset.."ButtonBottomLeft:Width"),getElementData(cTheme,imageset.."ButtonBottomLeft:Height"),
								getElementData(cTheme,imageset.."ButtonBottomLeft:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw,cpyy,cw-leftw-rightw,toph,
								getElementData(cTheme,imageset.."ButtonTop:X"),getElementData(cTheme,imageset.."ButtonTop:Y"),
								getElementData(cTheme,imageset.."ButtonTop:Width"),getElementData(cTheme,imageset.."ButtonTop:Height"),
								getElementData(cTheme,"images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw,cpyy+toplefth+(ch-toplefth-botlefth),cw-leftw-rightw,both,
								getElementData(cTheme,imageset.."ButtonBottom:X"),getElementData(cTheme,imageset.."ButtonBottom:Y"),
								getElementData(cTheme,imageset.."ButtonBottom:Width"),getElementData(cTheme,imageset.."ButtonBottom:Height"),
								getElementData(cTheme,imageset.."ButtonBottom:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,imageset.."ButtonBottomRight:Width"),botright,
								getElementData(cTheme,imageset.."ButtonBottomRight:X"),getElementData(cTheme,imageset.."ButtonBottomRight:Y"),
								getElementData(cTheme,imageset.."ButtonBottomRight:Width"),getElementData(cTheme,imageset.."ButtonBottomRight:Height"),
								getElementData(cTheme,imageset.."ButtonBottomRight:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy,getElementData(cTheme,imageset.."ButtonTopRight:Width"),getElementData(cTheme,imageset.."ButtonTopRight:Height"),
								getElementData(cTheme,imageset.."ButtonTopRight:X"),getElementData(cTheme,imageset.."ButtonTopRight:Y"),
								getElementData(cTheme,imageset.."ButtonTopRight:Width"),getElementData(cTheme,imageset.."ButtonTopRight:Height"),
								getElementData(cTheme,imageset.."ButtonTopRight:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toplefth,getElementData(cTheme,imageset.."ButtonRight:Width"),ch-toplefth-botlefth,
								getElementData(cTheme,imageset.."ButtonRight:X"),getElementData(cTheme,imageset.."ButtonRight:Y"),
								getElementData(cTheme,imageset.."ButtonRight:Width"),getElementData(cTheme,imageset.."ButtonRight:Height"),
								getElementData(cTheme,imageset.."ButtonRight:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw,cpyy+toplefth,cw-leftw-rightw,ch-toplefth-botlefth,
								getElementData(cTheme,imageset.."ButtonCenter:X"),getElementData(cTheme,imageset.."ButtonCenter:Y"),
								getElementData(cTheme,imageset.."ButtonCenter:Width"),getElementData(cTheme,imageset.."ButtonCenter:Height"),
								getElementData(cTheme,imageset.."ButtonCenter:images"),0,0,0,color,false)
							local title,font = dxGetText(component),dxGetFont(component)
							local tw = cw-leftw-rightw
							local th = ch-toplefth-botlefth
							
							local textWidth
							if (dxGetColorCoded(component)) then
								textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
							else
								textWidth = dxGetTextWidth(title,1,font)
							end
							if textWidth > tw-10 then
								while textWidth>tw-10 do
									title = title:sub(1,title:len()-6).."..."
									if (dxGetColorCoded(component)) then
										textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
									else
										textWidth = dxGetTextWidth(title,1,font)
									end
								end
							end
							
							local textHeight = dxGetFontHeight(1,font)
							local textX = cpxx+leftw
							local textY = cpyy+toplefth
							local textXX = cpxx+cw-leftw-rightw
							local textYY = cpyy+ch-toplefth
							if (dxGetColorCoded(component)) then
								dxDrawColorText(title,textX,textY,textXX,textYY,color,1,font,"center","center")
							else
								dxDrawText(title,textX,textY,textXX,textYY,color,1,font,"center","center")
							end
							--
						elseif (eType == "dxCheckBox") then
							local checked = dxCheckBoxGetSelected(component)
							local imageset  = "CheckboxNormal"
							if not checked then
								if (getElementData(component,"hover")) then
									imageset = "CheckboxHover"--
								else
									imageset = "CheckboxMark"
								end
							else
								if (getElementData(component,"hover")) then
									imageset = "CheckboxMarkHover" -- 
								else
									imageset = "CheckboxNormal" -- 
								end
							end
							
							dxDrawImageSection(cpx+cx,cpy+cy,cw,ch,
									getElementData(cTheme,imageset..":X"),getElementData(cTheme,imageset..":Y"),
									getElementData(cTheme,imageset..":Width"),getElementData(cTheme,imageset..":Height"),
									getElementData(cTheme,imageset..":images"),0,0,0,color,false)
							
							local title,font = dxGetText(component),dxGetFont(component)
								
							local tx = cx
							local th = ch					
							local textHeight = dxGetFontHeight(1,font)
							local textX = cpx+cx+25
							local textY = cpy+cy+((th-textHeight)/2)
							if (dxGetColorCoded(component)) then
								dxDrawColorText(title,textX,textY,textX,textY,color,1,font)
							else
								dxDrawText(title,textX,textY,textX,textY,color,1,font)
							end
						elseif (eType == "dxRadioButton") then
							local checked = dxRadioButtonGetSelected(component)
							local imageset  = "RadioButtonNormal"
							if not checked then
								if (getElementData(component,"hover")) then
									imageset = "RadioButtonHover"
								else
									imageset = "RadioButtonNormal"
								end
							else
								if (getElementData(component,"hover")) then
									imageset = "RadioButtonMarkHover"
								else
									imageset = "RadioButtonMark"
								end
							end
							
							dxDrawImageSection(cpx+cx,cpy+cy,cw,ch,
									getElementData(cTheme,imageset..":X"),getElementData(cTheme,imageset..":Y"),
									getElementData(cTheme,imageset..":Width"),getElementData(cTheme,imageset..":Height"),
									getElementData(cTheme,imageset..":images"),0,0,0,color,false)
							
							local title,font = dxGetText(component),dxGetFont(component)
								
							local tx = cx
							local th = ch					
							local textHeight = dxGetFontHeight(1,font)
							local textX = cpx+cx+25
							local textY = cpy+cy+((th-textHeight)/2)
							if (dxGetColorCoded(component)) then
								dxDrawColorText(title,textX,textY,textX,textY,color,1,font)
							else
								dxDrawText(title,textX,textY,textX,textY,color,1,font)
							end
						elseif (eType == "dxLabel") then					
							local title,font = dxGetText(component),dxGetFont(component)
							local tx = cx
							local th = ch					
							local textX = cpx+cx
							local textY = cpy+cy
							local tw = w-(textX-x)
							local scale = dxLabelGetScale(component)
							local textWidth = dxGetTextWidth(title,scale,font)
							if (dxGetColorCoded(component)) then
								textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x",""),scale,font)
							else
								textWidth = dxGetTextWidth(title,scale,font)
							end
							if textWidth > tw then
								while textWidth>tw do
									title = title:sub(1,title:len()-1)
									if (dxGetColorCoded(component)) then
										textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x",""),scale,font)
									else
										textWidth = dxGetTextWidth(title,scale,font)
									end
								end
							end
							local alignX,alignY = dxLabelGetHorizontalAlign(),
								dxLabelGetVerticalAlign()
							
							if (dxGetColorCoded(component)) then
								dxDrawColorText(title,textX,textY,textX,textY,color,scale,font)
							else
								dxDrawText(title,textX,textY,textX,textY,color,scale,font)
							end
						elseif (eType == "dxStaticImage") then
							local path = getElementData(component,"image")
							local rotation = getElementData(component,"rotation")
							if (getElementData(component,"Section")) then
								local sx,sy,sw,sh = getElementData(component,"Section:x"),getElementData(component,"Section:y"),getElementData(component,"Section:width"),getElementData(component,"Section:height")
								dxDrawImageSection(cpx+cx,cpx+cy,cw,ch,sx,sy,sw,sh,path,rotation)
							else
								dxDrawImage(cpx+cx,cpx+cy,cw,ch,path,rotation)
							end
						elseif (eType == "dxProgressBar") then
							local cpxx = cpx+cx
							local cpyy = cpy+cy
							
							local leftw,rightw = getElementData(cTheme,"ProgressLeft:Width"),getElementData(cTheme,"ProgressRight:Width")
							local toplefth,botlefth = getElementData(cTheme,"ProgressTopLeft:Height"),getElementData(cTheme,"ProgressBottomLeft:Height")
							local toprigth,botrigth = getElementData(cTheme,"ProgressTopRight:Height"),getElementData(cTheme,"ProgressBottomRight:Height")
							local toph,both = getElementData(cTheme,"ProgressTop:Height"),getElementData(cTheme,"ProgressBottom:Height")
							
							dxDrawImageSection(cpxx,cpyy,getElementData(cTheme,"ProgressTopLeft:Width"),toplefth,
								getElementData(cTheme,"ProgressTopLeft:X"),getElementData(cTheme,"ProgressTopLeft:Y"),
								getElementData(cTheme,"ProgressTopLeft:Width"),getElementData(cTheme,"ProgressTopLeft:Height"),
								getElementData(cTheme,"ProgressTopLeft:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx,cpyy+toplefth,getElementData(cTheme,"ProgressLeft:Width"),ch-toplefth-botlefth,
								getElementData(cTheme,"ProgressLeft:X"),getElementData(cTheme,"ProgressLeft:Y"),
								getElementData(cTheme,"ProgressLeft:Width"),getElementData(cTheme,"ProgressLeft:Height"),
								getElementData(cTheme,"ProgressLeft:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx,cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,"ProgressBottomLeft:Width"),botlefth,
								getElementData(cTheme,"ProgressBottomLeft:X"),getElementData(cTheme,"ProgressBottomLeft:Y"),
								getElementData(cTheme,"ProgressBottomLeft:Width"),getElementData(cTheme,"ProgressBottomLeft:Height"),
								getElementData(cTheme,"ProgressBottomLeft:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+getElementData(cTheme,"ProgressTopLeft:Width"),cpyy,cw-leftw-rightw,toph,
								getElementData(cTheme,"ProgressTop:X"),getElementData(cTheme,"ProgressTop:Y"),
								getElementData(cTheme,"ProgressTop:Width"),getElementData(cTheme,"ProgressTop:Height"),
								getElementData(cTheme,"ProgressTop:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+getElementData(cTheme,"ProgressTopLeft:Width"),cpyy+toplefth+(ch-toplefth-botlefth),cw-leftw-rightw,both,
								getElementData(cTheme,"ProgressBottom:X"),getElementData(cTheme,"ProgressBottom:Y"),
								getElementData(cTheme,"ProgressBottom:Width"),getElementData(cTheme,"ProgressBottom:Height"),
								getElementData(cTheme,"ProgressBottom:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,"ProgressBottomRight:Width"),botrigth,
								getElementData(cTheme,"ProgressBottomRight:X"),getElementData(cTheme,"ProgressBottomRight:Y"),
								getElementData(cTheme,"ProgressBottomRight:Width"),getElementData(cTheme,"ProgressBottomRight:Height"),
								getElementData(cTheme,"ProgressBottomRight:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toprigth,getElementData(cTheme,"ProgressRight:Width"),ch-toplefth-botlefth,
								getElementData(cTheme,"ProgressRight:X"),getElementData(cTheme,"ProgressRight:Y"),
								getElementData(cTheme,"ProgressRight:Width"),getElementData(cTheme,"ProgressRight:Height"),
								getElementData(cTheme,"ProgressRight:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy,getElementData(cTheme,"ProgressTopRight:Width"),toprigth,
								getElementData(cTheme,"ProgressTopRight:X"),getElementData(cTheme,"ProgressTopRight:Y"),
								getElementData(cTheme,"ProgressTopRight:Width"),getElementData(cTheme,"ProgressTopRight:Height"),
								getElementData(cTheme,"ProgressTopRight:images"),0,0,0,color,false)
							dxDrawImageSection(cpxx+leftw,cpyy+toplefth,cw-leftw-rightw,ch-toplefth-botlefth,
								getElementData(cTheme,"ProgressBackground:X"),getElementData(cTheme,"ProgressBackground:Y"),
								getElementData(cTheme,"ProgressBackground:Width"),getElementData(cTheme,"ProgressBackground:Height"),
								getElementData(cTheme,"ProgressBackground:images"),0,0,0,color,false)
							local prog = dxProgressBarGetProgress(component)
							local max = dxProgressBarGetMaxProgress(component)
							local width__ = cw-leftw-rightw
							-- max width__
							-- prog x
							local width_ = (prog*width__) / max
							local progressColor = getElementData(component,"progressColor")
							if type(progressColor) ~= "string" then
								dxDrawRectangle(cpxx+leftw,cpyy+toplefth,width_,ch-toplefth-botlefth,progressColor,false)
							else
								dxDrawImageSection(cpxx+leftw,cpyy+toplefth,width_,ch-toplefth-botlefth,
									getElementData(cTheme,"ProgressBarLitSegment:X"),getElementData(cTheme,"ProgressBarLitSegment:Y"),
									getElementData(cTheme,"ProgressBarLitSegment:Width"),getElementData(cTheme,"ProgressBarLitSegment:Height"),
									getElementData(cTheme,"ProgressBarLitSegment:images"),0,0,0,tocolor(255,255,255),false)
							end
						elseif (eType == "dxScrollBar") then
							local cpxx = cpx+cx
							local cpyy = cpy+cy
							local type_ = getElementData(component,"type")
							if (type_ == "Vertical") then
								local upArrowH=getElementData(cTheme,"ScrollUpArrow:Height")
								local downArrowH=getElementData(cTheme,"ScrollDownArrow:Height")
								dxDrawImageSection(cpxx,cpyy,cw,upArrowH,
									getElementData(cTheme,"ScrollUpArrow:X"),getElementData(cTheme,"ScrollUpArrow:Y"),
									getElementData(cTheme,"ScrollUpArrow:Width"),getElementData(cTheme,"ScrollUpArrow:Height"),
									getElementData(cTheme,"ScrollUpArrow:images"),0,0,0,color,false)
									
								dxDrawImageSection(cpxx,cpyy+upArrowH,cw,ch+getElementData(cTheme,"ScrollbarThumb:Height"),
									getElementData(cTheme,"VertScrollContainer:X"),getElementData(cTheme,"VertScrollContainer:Y"),
									getElementData(cTheme,"VertScrollContainer:Width"),getElementData(cTheme,"VertScrollContainer:Height"),
									getElementData(cTheme,"VertScrollContainer:images"),0,0,0,color,false)
								
								dxDrawImageSection(cpxx,cpyy+upArrowH+ch+getElementData(cTheme,"ScrollbarThumb:Height"),cw,downArrowH,
									getElementData(cTheme,"ScrollDownArrow:X"),getElementData(cTheme,"ScrollDownArrow:Y"),
									getElementData(cTheme,"ScrollDownArrow:Width"),getElementData(cTheme,"ScrollDownArrow:Height"),
									getElementData(cTheme,"ScrollDownArrow:images"),0,0,0,color,false)
								
								local ratio = dxScrollBarGetScrollPercent(component)/50
								local yScroll = cpyy+upArrowH+(ch/2)*ratio
								local c = (cw-getElementData(cTheme,"ScrollbarThumb:Width"))/2
								dxDrawImageSection(cpxx+c,yScroll,getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
									getElementData(cTheme,"ScrollbarThumb:X"),getElementData(cTheme,"ScrollbarThumb:Y"),
									getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
									getElementData(cTheme,"ScrollbarThumb:images"),0,0,0,color,false)	
							else
								local upArrowW=getElementData(cTheme,"ScrollLeftArrow:Width")
								local downArrowW=getElementData(cTheme,"ScrollRightArrow:Height")
								dxDrawImageSection(cpxx,cpyy,upArrowW,ch,
									getElementData(cTheme,"ScrollLeftArrow:X"),getElementData(cTheme,"ScrollLeftArrow:Y"),
									getElementData(cTheme,"ScrollLeftArrow:Width"),getElementData(cTheme,"ScrollLeftArrow:Height"),
									getElementData(cTheme,"ScrollLeftArrow:images"),0,0,0,color,false)
								dxDrawImageSection(cpxx+upArrowW,cpyy,cw+getElementData(cTheme,"ScrollbarThumb:Width"),ch,
									getElementData(cTheme,"HorzScrollContainer:X"),getElementData(cTheme,"HorzScrollContainer:Y"),
									getElementData(cTheme,"HorzScrollContainer:Width"),getElementData(cTheme,"HorzScrollContainer:Height"),
									getElementData(cTheme,"HorzScrollContainer:images"),0,0,0,color,false)
								
								dxDrawImageSection(cpxx+upArrowW+cw+getElementData(cTheme,"ScrollbarThumb:Width"),cpyy,downArrowW,ch,
									getElementData(cTheme,"ScrollRightArrow:X"),getElementData(cTheme,"ScrollRightArrow:Y"),
									getElementData(cTheme,"ScrollRightArrow:Width"),getElementData(cTheme,"ScrollRightArrow:Height"),
									getElementData(cTheme,"ScrollRightArrow:images"),0,0,0,color,false)
								
								local ratio = dxScrollBarGetScrollPercent(component)/50
								local xScroll = cpxx+upArrowW+(cw/2)*ratio
								local c = (ch-getElementData(cTheme,"ScrollbarThumb:Height"))/2
								dxDrawImageSection(xScroll,cpyy+c,getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
									getElementData(cTheme,"ScrollbarThumb:X"),getElementData(cTheme,"ScrollbarThumb:Y"),
									getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
									getElementData(cTheme,"ScrollbarThumb:images"),0,0,0,color,false)
							end
						elseif (eType == "dxSpinner") then
							local cpxx = cpx+cx
							local cpyy = cpy+cy
							local optWidth = getElementData(cTheme,"SpinnerIncBackground:Width")	
							
							dxDrawImageSection(cpxx,cpyy,cw-optWidth,ch,
								getElementData(cTheme,"SpinnerBackground:X"),getElementData(cTheme,"SpinnerBackground:Y"),
								getElementData(cTheme,"SpinnerBackground:Width"),getElementData(cTheme,"SpinnerBackground:Height"),
								getElementData(cTheme,"SpinnerBackground:images"),0,0,0,tocolor(255,255,255), false)
								
							dxDrawImageSection(cpxx+cw-optWidth,cpyy,optWidth,ch,
								getElementData(cTheme,"SpinnerIncBackground:X"),getElementData(cTheme,"SpinnerIncBackground:Y"),
								getElementData(cTheme,"SpinnerIncBackground:Width"),getElementData(cTheme,"SpinnerIncBackground:Height"),
								getElementData(cTheme,"SpinnerIncBackground:images"),0,0,0,tocolor(255,255,255), false)
							local str = tostring(dxSpinnerGetPosition(component))
							if ( dxSpinnerGetPosition(component) == dxSpinnerGetMin(component) ) then
								str = "#FF0000"..str
							elseif ( dxSpinnerGetPosition(component) == dxSpinnerGetMax(component) ) then
								str = "#FF0000"..str
							end
							dxDrawColorText(tostring(str),cpxx,cpyy,cpxx+(cw-optWidth),cpyy+ch,color,1,font,"right","center")
						end
					end
				end
			end
		end
		local cpx = getElementData(dxGetRootPane(),"x")
		local cpy = getElementData(dxGetRootPane(),"y")
		for _,component in ipairs(getElementChildren(dxGetRootPane())) do
			if dxGetVisible(component) then
				local eType = getElementType(component)
				local cTheme = getElementData(component,"theme")
						or getElementData(getElementParent(component),"theme")
				
				local cx,cy,cw,ch = getElementData(component,"x"),getElementData(component,"y"),
								   getElementData(component,"width"),
								   getElementData(component,"height")
								   
				local color = getElementData(component,"color")
								   
				for _,aElements in ipairs(attachedElements) do
					if ( aElements[1] == component ) then
						guiSetPosition(aElements[2],cpx+cx+aElements[3],cpy+cy+aElements[4],false)
					end
				end
				if (eType=="dxButton") then
					local cpxx = cpx+cx
					local cpyy = cpy+cy
					-- Button drawings
					local imageset = "S"
					if ( getElementData(component,"hover") ) then
						imageset = ""
					end
					
					local leftw,rightw = getElementData(cTheme,imageset.."ButtonLeft:Width"),getElementData(cTheme,imageset.."ButtonRight:Width")
					local toplefth,botlefth = getElementData(cTheme,imageset.."ButtonTopLeft:Height"),getElementData(cTheme,imageset.."ButtonBottomLeft:Height")
					local toprigth,botright = getElementData(cTheme,imageset.."ButtonTopRight:Height"),getElementData(cTheme,imageset.."ButtonBottomRight:Height")
					local toph,both = getElementData(cTheme,imageset.."ButtonTop:Height"), getElementData(cTheme,imageset.."ButtonBottom:Height")
					dxDrawImageSection(cpxx,cpyy,getElementData(cTheme,imageset.."ButtonTopLeft:Width"),getElementData(cTheme,imageset.."ButtonTopLeft:Height"),
						getElementData(cTheme,imageset.."ButtonTopLeft:X"),getElementData(cTheme,imageset.."ButtonTopLeft:Y"),
						getElementData(cTheme,imageset.."ButtonTopLeft:Width"),getElementData(cTheme,imageset.."ButtonTopLeft:Height"),
						getElementData(cTheme,imageset.."ButtonTopLeft:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx,cpyy+toplefth,getElementData(cTheme,imageset.."ButtonLeft:Width"),ch-toplefth-botlefth,
						getElementData(cTheme,imageset.."ButtonLeft:X"),getElementData(cTheme,imageset.."ButtonLeft:Y"),
						getElementData(cTheme,imageset.."ButtonLeft:Width"),getElementData(cTheme,imageset.."ButtonLeft:Height"),
						getElementData(cTheme,imageset.."ButtonLeft:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx,cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,imageset.."ButtonBottomLeft:Width"),botlefth,
						getElementData(cTheme,imageset.."ButtonBottomLeft:X"),getElementData(cTheme,imageset.."ButtonBottomLeft:Y"),
						getElementData(cTheme,imageset.."ButtonBottomLeft:Width"),getElementData(cTheme,imageset.."ButtonBottomLeft:Height"),
						getElementData(cTheme,imageset.."ButtonBottomLeft:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw,cpyy,cw-leftw-rightw,toph,
						getElementData(cTheme,imageset.."ButtonTop:X"),getElementData(cTheme,imageset.."ButtonTop:Y"),
						getElementData(cTheme,imageset.."ButtonTop:Width"),getElementData(cTheme,imageset.."ButtonTop:Height"),
						getElementData(cTheme,imageset.."ButtonTop:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw,cpyy+toplefth+(ch-toplefth-botlefth),cw-leftw-rightw,both,
						getElementData(cTheme,imageset.."ButtonBottom:X"),getElementData(cTheme,imageset.."ButtonBottom:Y"),
						getElementData(cTheme,imageset.."ButtonBottom:Width"),getElementData(cTheme,imageset.."ButtonBottom:Height"),
						getElementData(cTheme,imageset.."ButtonBottom:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,imageset.."ButtonBottomRight:Width"),botright,
						getElementData(cTheme,imageset.."ButtonBottomRight:X"),getElementData(cTheme,imageset.."ButtonBottomRight:Y"),
						getElementData(cTheme,imageset.."ButtonBottomRight:Width"),getElementData(cTheme,imageset.."ButtonBottomRight:Height"),
						getElementData(cTheme,imageset.."ButtomBottomRight:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy,getElementData(cTheme,imageset.."ButtonTopRight:Width"),getElementData(cTheme,imageset.."ButtonTopRight:Height"),
						getElementData(cTheme,imageset.."ButtonTopRight:X"),getElementData(cTheme,imageset.."ButtonTopRight:Y"),
						getElementData(cTheme,imageset.."ButtonTopRight:Width"),getElementData(cTheme,imageset.."ButtonTopRight:Height"),
						getElementData(cTheme,imageset.."ButtonTopRight:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toplefth,getElementData(cTheme,imageset.."ButtonRight:Width"),ch-toplefth-botlefth,
						getElementData(cTheme,imageset.."ButtonRight:X"),getElementData(cTheme,imageset.."ButtonRight:Y"),
						getElementData(cTheme,imageset.."ButtonRight:Width"),getElementData(cTheme,imageset.."ButtonRight:Height"),
						getElementData(cTheme,imageset.."ButtonRight:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw,cpyy+toplefth,cw-leftw-rightw,ch-toplefth-botlefth,
						getElementData(cTheme,imageset.."ButtonCenter:X"),getElementData(cTheme,imageset.."ButtonCenter:Y"),
						getElementData(cTheme,imageset.."ButtonCenter:Width"),getElementData(cTheme,imageset.."ButtonCenter:Height"),
						getElementData(cTheme,imageset.."ButtonCenter:images"),0,0,0,color,false)
					local title,font = dxGetText(component),dxGetFont(component)
					local tw = cw-leftw-rightw
					local th = ch-toplefth-botlefth
					
					local textWidth
					if (dxGetColorCoded(component)) then
						textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
					else
						textWidth = dxGetTextWidth(title,1,font)
					end
					if textWidth > tw-10 then
						while textWidth>tw-10 do
							title = title:sub(1,title:len()-6).."..."
							if (dxGetColorCoded(component)) then
								textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x", ""),1,font)
							else
								textWidth = dxGetTextWidth(title,1,font)
							end
						end
					end
					
					local textHeight = dxGetFontHeight(1,font)
					local textX = cpxx+leftw
					local textY = cpyy+toplefth
					local textXX = cpxx+cw-leftw-rightw
					local textYY = cpyy+ch-toplefth
					if (dxGetColorCoded(component)) then
						dxDrawColorText(title,textX,textY,textXX,textYY,color,1,font,"center","center")
					else
						dxDrawText(title,textX,textY,textXX,textYY,color,1,font,"center","center")
					end
					--
				elseif (eType == "dxCheckBox") then
					local checked = dxCheckBoxGetSelected(component)
					local imageset  = "CheckboxNormal"
					if not checked then
						if (getElementData(component,"hover")) then
							imageset = "CheckboxHover"--
						else
							imageset = "CheckboxMark"
						end
					else
						if (getElementData(component,"hover")) then
							imageset = "CheckboxMarkHover" -- 
						else
							imageset = "CheckboxNormal" -- 
						end
					end
					
					dxDrawImageSection(cpx+cx,cpy+cy,cw,ch,
							getElementData(cTheme,imageset..":X"),getElementData(cTheme,imageset..":Y"),
							getElementData(cTheme,imageset..":Width"),getElementData(cTheme,imageset..":Height"),
							getElementData(cTheme,imageset..":images"),0,0,0,color,false)
					
					local title,font = dxGetText(component),dxGetFont(component)
						
					local tx = cx
					local th = ch					
					local textHeight = dxGetFontHeight(1,font)
					local textX = cpx+cx+25
					local textY = cpy+cy+((th-textHeight)/2)
					if (dxGetColorCoded(component)) then
						dxDrawColorText(title,textX,textY,textX,textY,color,1,font)
					else
						dxDrawText(title,textX,textY,textX,textY,color,1,font)
					end
				elseif (eType == "dxRadioButton") then
					local checked = dxRadioButtonGetSelected(component)
					local imageset  = "RadioButtonNormal"
					if not checked then
						if (getElementData(component,"hover")) then
							imageset = "RadioButtonHover"
						else
							imageset = "RadioButtonNormal"
						end
					else
						if (getElementData(component,"hover")) then
							imageset = "RadioButtonMarkHover"
						else
							imageset = "RadioButtonMark"
						end
					end
					
					dxDrawImageSection(cpx+cx,cpy+cy,cw,ch,
							getElementData(cTheme,imageset..":X"),getElementData(cTheme,imageset..":Y"),
							getElementData(cTheme,imageset..":Width"),getElementData(cTheme,imageset..":Height"),
							getElementData(cTheme,imageset..":images"),0,0,0,color,false)
					
					local title,font = dxGetText(component),dxGetFont(component)
						
					local tx = cx
					local th = ch					
					local textHeight = dxGetFontHeight(1,font)
					local textX = cpx+cx+25
					local textY = cpy+cy+((th-textHeight)/2)
					if (dxGetColorCoded(component)) then
						dxDrawColorText(title,textX,textY,textX,textY,color,1,font)
					else
						dxDrawText(title,textX,textY,textX,textY,color,1,font)
					end
				elseif (eType == "dxLabel") then					
					local title,font = dxGetText(component),dxGetFont(component)
					local tx = cx
					local th = ch					
					local textX = cpx+cx
					local textY = cpy+cy
					local tw = w-(textX-x)
					local scale = dxLabelGetScale(component)
					local textWidth = dxGetTextWidth(title,scale,font)
					if (dxGetColorCoded(component)) then
						textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x",""),scale,font)
					else
						textWidth = dxGetTextWidth(title,scale,font)
					end
					if textWidth > tw then
						while textWidth>tw do
							title = title:sub(1,title:len()-1)
							if (dxGetColorCoded(component)) then
								textWidth = dxGetTextWidth(title:gsub("#%x%x%x%x%x%x",""),scale,font)
							else
								textWidth = dxGetTextWidth(title,scale,font)
							end
						end
					end
					local alignX,alignY = dxLabelGetHorizontalAlign(),
						dxLabelGetVerticalAlign()
					
					if (dxGetColorCoded(component)) then
						dxDrawColorText(title,textX,textY,textX,textY,color,scale,font)
					else
						dxDrawText(title,textX,textY,textX,textY,color,scale,font)
					end
				elseif (eType == "dxStaticImage") then
					local path = getElementData(component,"image")
					local rotation = getElementData(component,"rotation")
					if (getElementData(component,"Section")) then
						local sx,sy,sw,sh = getElementData(component,"Section:x"),getElementData(component,"Section:y"),getElementData(component,"Section:width"),getElementData(component,"Section:height")
						dxDrawImageSection(cpx+cx,cpx+cy,cw,ch,sx,sy,sw,sh,path,rotation)
					else
						dxDrawImage(cpx+cx,cpx+cy,cw,ch,path,rotation)
					end
				elseif (eType == "dxProgressBar") then
					local cpxx = cpx+cx
					local cpyy = cpy+cy
					
					local leftw,rightw = getElementData(cTheme,"ProgressLeft:Width"),getElementData(cTheme,"ProgressRight:Width")
					local toplefth,botlefth = getElementData(cTheme,"ProgressTopLeft:Height"),getElementData(cTheme,"ProgressBottomLeft:Height")
					local toprigth,botrigth = getElementData(cTheme,"ProgressTopRight:Height"),getElementData(cTheme,"ProgressBottomRight:Height")
					local toph,both = getElementData(cTheme,"ProgressTop:Height"),getElementData(cTheme,"ProgressBottom:Height")
					
					dxDrawImageSection(cpxx,cpyy,getElementData(cTheme,"ProgressTopLeft:Width"),toplefth,
						getElementData(cTheme,"ProgressTopLeft:X"),getElementData(cTheme,"ProgressTopLeft:Y"),
						getElementData(cTheme,"ProgressTopLeft:Width"),getElementData(cTheme,"ProgressTopLeft:Height"),
						getElementData(cTheme,"ProgressTopLeft:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx,cpyy+toplefth,getElementData(cTheme,"ProgressLeft:Width"),ch-toplefth-botlefth,
						getElementData(cTheme,"ProgressLeft:X"),getElementData(cTheme,"ProgressLeft:Y"),
						getElementData(cTheme,"ProgressLeft:Width"),getElementData(cTheme,"ProgressLeft:Height"),
						getElementData(cTheme,"ProgressLeft:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx,cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,"ProgressBottomLeft:Width"),botlefth,
						getElementData(cTheme,"ProgressBottomLeft:X"),getElementData(cTheme,"ProgressBottomLeft:Y"),
						getElementData(cTheme,"ProgressBottomLeft:Width"),getElementData(cTheme,"ProgressBottomLeft:Height"),
						getElementData(cTheme,"ProgressBottomLeft:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+getElementData(cTheme,"ProgressTopLeft:Width"),cpyy,cw-leftw-rightw,toph,
						getElementData(cTheme,"ProgressTop:X"),getElementData(cTheme,"ProgressTop:Y"),
						getElementData(cTheme,"ProgressTop:Width"),getElementData(cTheme,"ProgressTop:Height"),
						getElementData(cTheme,"ProgressTop:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+getElementData(cTheme,"ProgressTopLeft:Width"),cpyy+toplefth+(ch-toplefth-botlefth),cw-leftw-rightw,both,
						getElementData(cTheme,"ProgressBottom:X"),getElementData(cTheme,"ProgressBottom:Y"),
						getElementData(cTheme,"ProgressBottom:Width"),getElementData(cTheme,"ProgressBottom:Height"),
						getElementData(cTheme,"ProgressBottom:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toplefth+(ch-toplefth-botlefth),getElementData(cTheme,"ProgressBottomRight:Width"),botrigth,
						getElementData(cTheme,"ProgressBottomRight:X"),getElementData(cTheme,"ProgressBottomRight:Y"),
						getElementData(cTheme,"ProgressBottomRight:Width"),getElementData(cTheme,"ProgressBottomRight:Height"),
						getElementData(cTheme,"ProgressBottomRight:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy+toprigth,getElementData(cTheme,"ProgressRight:Width"),ch-toplefth-botlefth,
						getElementData(cTheme,"ProgressRight:X"),getElementData(cTheme,"ProgressRight:Y"),
						getElementData(cTheme,"ProgressRight:Width"),getElementData(cTheme,"ProgressRight:Height"),
						getElementData(cTheme,"ProgressRight:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw+(cw-leftw-rightw),cpyy,getElementData(cTheme,"ProgressTopRight:Width"),toprigth,
						getElementData(cTheme,"ProgressTopRight:X"),getElementData(cTheme,"ProgressTopRight:Y"),
						getElementData(cTheme,"ProgressTopRight:Width"),getElementData(cTheme,"ProgressTopRight:Height"),
						getElementData(cTheme,"ProgressTopRight:images"),0,0,0,color,false)
					dxDrawImageSection(cpxx+leftw,cpyy+toplefth,cw-leftw-rightw,ch-toplefth-botlefth,
						getElementData(cTheme,"ProgressBackground:X"),getElementData(cTheme,"ProgressBackground:Y"),
						getElementData(cTheme,"ProgressBackground:Width"),getElementData(cTheme,"ProgressBackground:Height"),
						getElementData(cTheme,"ProgressBackground:images"),0,0,0,color,false)
					local prog = dxProgressBarGetProgress(component)
					local max = dxProgressBarGetMaxProgress(component)
					local width__ = cw-leftw-rightw
					-- max width__
					-- prog x
					local width_ = (prog*width__) / max
					local progressColor = getElementData(component,"progressColor")
					if type(progressColor) ~= "string" then
						dxDrawRectangle(cpxx+leftw,cpyy+toplefth,width_,ch-toplefth-botlefth,progressColor,false)
					else
						dxDrawImageSection(cpxx+leftw,cpyy+toplefth,width_,ch-toplefth-botlefth,
							getElementData(cTheme,"ProgressBarLitSegment:X"),getElementData(cTheme,"ProgressBarLitSegment:Y"),
							getElementData(cTheme,"ProgressBarLitSegment:Width"),getElementData(cTheme,"ProgressBarLitSegment:Height"),
							getElementData(cTheme,"ProgressBarLitSegment:images"),0,0,0,tocolor(255,255,255),false)
					end
				elseif (eType == "dxScrollBar") then
					local cpxx = cpx+cx
					local cpyy = cpy+cy
					local type_ = getElementData(component,"type")
					if (type_ == "Vertical") then
						local upArrowH=getElementData(cTheme,"ScrollUpArrow:Height")
						local downArrowH=getElementData(cTheme,"ScrollDownArrow:Height")
						dxDrawImageSection(cpxx,cpyy,cw,upArrowH,
							getElementData(cTheme,"ScrollUpArrow:X"),getElementData(cTheme,"ScrollUpArrow:Y"),
							getElementData(cTheme,"ScrollUpArrow:Width"),getElementData(cTheme,"ScrollUpArrow:Height"),
							getElementData(cTheme,"ScrollUpArrow:images"),0,0,0,color,false)
							
						dxDrawImageSection(cpxx,cpyy+upArrowH,cw,ch+getElementData(cTheme,"ScrollbarThumb:Height"),
							getElementData(cTheme,"VertScrollContainer:X"),getElementData(cTheme,"VertScrollContainer:Y"),
							getElementData(cTheme,"VertScrollContainer:Width"),getElementData(cTheme,"VertScrollContainer:Height"),
							getElementData(cTheme,"VertScrollContainer:images"),0,0,0,color,false)
						
						dxDrawImageSection(cpxx,cpyy+upArrowH+ch+getElementData(cTheme,"ScrollbarThumb:Height"),cw,downArrowH,
							getElementData(cTheme,"ScrollDownArrow:X"),getElementData(cTheme,"ScrollDownArrow:Y"),
							getElementData(cTheme,"ScrollDownArrow:Width"),getElementData(cTheme,"ScrollDownArrow:Height"),
							getElementData(cTheme,"ScrollDownArrow:images"),0,0,0,color,false)
						
						local ratio = dxScrollBarGetScrollPercent(component)/50
						local yScroll = cpyy+upArrowH+(ch/2)*ratio
						local c = (cw-getElementData(cTheme,"ScrollbarThumb:Width"))/2
						dxDrawImageSection(cpxx+c,yScroll,getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
							getElementData(cTheme,"ScrollbarThumb:X"),getElementData(cTheme,"ScrollbarThumb:Y"),
							getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
							getElementData(cTheme,"ScrollbarThumb:images"),0,0,0,color,false)	
					else
						local upArrowW=getElementData(cTheme,"ScrollLeftArrow:Width")
						local downArrowW=getElementData(cTheme,"ScrollRightArrow:Height")
						dxDrawImageSection(cpxx,cpyy,upArrowW,ch,
							getElementData(cTheme,"ScrollLeftArrow:X"),getElementData(cTheme,"ScrollLeftArrow:Y"),
							getElementData(cTheme,"ScrollLeftArrow:Width"),getElementData(cTheme,"ScrollLeftArrow:Height"),
							getElementData(cTheme,"ScrollLeftArrow:images"),0,0,0,color,false)
						dxDrawImageSection(cpxx+upArrowW,cpyy,cw+getElementData(cTheme,"ScrollbarThumb:Width"),ch,
							getElementData(cTheme,"HorzScrollContainer:X"),getElementData(cTheme,"HorzScrollContainer:Y"),
							getElementData(cTheme,"HorzScrollContainer:Width"),getElementData(cTheme,"HorzScrollContainer:Height"),
							getElementData(cTheme,"HorzScrollContainer:images"),0,0,0,color,false)
						
						dxDrawImageSection(cpxx+upArrowW+cw+getElementData(cTheme,"ScrollbarThumb:Width"),cpyy,downArrowW,ch,
							getElementData(cTheme,"ScrollRightArrow:X"),getElementData(cTheme,"ScrollRightArrow:Y"),
							getElementData(cTheme,"ScrollRightArrow:Width"),getElementData(cTheme,"ScrollRightArrow:Height"),
							getElementData(cTheme,"ScrollRightArrow:images"),0,0,0,color,false)
						
						local ratio = dxScrollBarGetScrollPercent(component)/50
						local xScroll = cpxx+upArrowW+(cw/2)*ratio
						local c = (ch-getElementData(cTheme,"ScrollbarThumb:Height"))/2
						dxDrawImageSection(xScroll,cpyy+c,getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
							getElementData(cTheme,"ScrollbarThumb:X"),getElementData(cTheme,"ScrollbarThumb:Y"),
							getElementData(cTheme,"ScrollbarThumb:Width"),getElementData(cTheme,"ScrollbarThumb:Height"),
							getElementData(cTheme,"ScrollbarThumb:images"),0,0,0,color,false)	
					end
				elseif (eType == "dxSpinner") then
					local cpxx = cpx+cx
					local cpyy = cpy+cy
					local optWidth = getElementData(cTheme,"SpinnerIncBackground:Width")	
					
					dxDrawImageSection(cpxx,cpyy,cw-optWidth,ch,
						getElementData(cTheme,"SpinnerBackground:X"),getElementData(cTheme,"SpinnerBackground:Y"),
						getElementData(cTheme,"SpinnerBackground:Width"),getElementData(cTheme,"SpinnerBackground:Height"),
						getElementData(cTheme,"SpinnerBackground:images"),0,0,0,tocolor(255,255,255), false)
						
					dxDrawImageSection(cpxx+cw-optWidth,cpyy,optWidth,ch,
						getElementData(cTheme,"SpinnerIncBackground:X"),getElementData(cTheme,"SpinnerIncBackground:Y"),
						getElementData(cTheme,"SpinnerIncBackground:Width"),getElementData(cTheme,"SpinnerIncBackground:Height"),
						getElementData(cTheme,"SpinnerIncBackground:images"),0,0,0,tocolor(255,255,255), false)
					local str = tostring(dxSpinnerGetPosition(component))
					if ( dxSpinnerGetPosition(component) == dxSpinnerGetMin(component) ) then
						str = "#FF0000"..str
					elseif ( dxSpinnerGetPosition(component) == dxSpinnerGetMax(component) ) then
						str = "#FF0000"..str
					end
					dxDrawColorText(tostring(str),cpxx,cpyy,cpxx+(cw-optWidth),cpyy+ch,color,1,font,"right","center")
				end
			end
		end
	end
)

addEventHandler("onClientClick",getRootElement(),
	function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld)
		if (isElement(clickedWorld)) then
			local cWorld = string.find(getElementType(clickedWorld),"gui-")
			if (cWorld ~= nil) then
				return
			end
		end
		if (button == "left" and state=="down") then
			for _,wnd in ipairs(getElementsByType("dxWindow")) do
				if dxGetVisible(wnd) and getElementData(getElementParent(wnd),"visible") then
					setElementData(wnd,"clicked",false)
					setElementData(wnd,"isMoving",false)
					local x,y = getElementData(wnd,"x"),getElementData(wnd,"y")
					local tx,ty = getElementData(wnd,"Title:x"),getElementData(wnd,"Title:y")
					local width = getElementData(wnd,"width")
					local theme = getElementData(wnd,"theme")
					local height = getElementData(theme,"TitleBarTopRight:Height")
					if (intersect(x,y,x+width,y+getElementData(wnd,"height"),absoluteX,absoluteY)) then
						setElementData(wnd,"clicked",true)
					end
					if (intersect(tx,ty,tx+width,ty+height,absoluteX,absoluteY)) then
						if getElementData(wnd,"movable") then
							setElementData(wnd,"isMoving",true)
							setElementData(wnd,"Move:x",absoluteX-getElementData(wnd,"Title:x"))
							setElementData(wnd,"Move:y",absoluteY-getElementData(wnd,"Title:y"))
						end
					end
				end
			end
		end
		
		if (button == "left" and state=="up") then
			for _,wnd in ipairs(getElementsByType("dxWindow")) do
				setElementData(wnd,"isMoving",false)
				removeElementData(wnd,"Move:x")
				removeElementData(wnd,"Move:y")
			end
		end
	end)

addEventHandler("onClientClick",getRootElement(),
	function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld)
		if (isElement(clickedWorld)) then
			local cWorld = string.find(getElementType(clickedWorld),"gui-")
			if (cWorld ~= nil) then
				return
			end
		end
		for _,element in ipairs(getElementsByType("dxButton")) do
			if dxGetVisible(element) and getElementData(getElementParent(element),"visible") then
				local parentX = getElementData(getElementParent(element),"x")
				local parentY = getElementData(getElementParent(element),"y")
				if (getElementType(getElementParent(element)) == "dxWindow") then
					parentY = parentY + getElementData(getElementData(getElementParent(element),"theme"),"TitleBarTopLeft:Height")-1
				end
				if isCursorShowing() then
					local x,y = 
						parentX+getElementData(element,"x"),parentY+getElementData(element,"y")
					local width = getElementData(element,"width")
					local height = getElementData(element,"height")
					if (intersect(x,y,x+width,y+height,absoluteX,absoluteY)) then
						triggerEvent("onClientDXClick",element,button,state,absoluteX,absoluteY)
					end
				end
			end
		end
	end)
	
addEventHandler("onClientDoubleClick",getRootElement(),
	function(button, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld)
		if (isElement(clickedWorld)) then
			local cWorld = string.find(getElementType(clickedWorld),"gui-")
			if (cWorld ~= nil) then
				return
			end
		end
		for _,element in ipairs(getElementsByType("dxButton")) do
			if dxGetVisible(element) and getElementData(getElementParent(element),"visible") then
				local parentX = getElementData(getElementParent(element),"x")
				local parentY = getElementData(getElementParent(element),"y")
				if (getElementType(getElementParent(element)) == "dxWindow") then
					parentY = parentY + getElementData(getElementData(getElementParent(element),"theme"),"TitleBarTopLeft:Height")-1
				end
				if isCursorShowing() then
					local x,y = 
						parentX+getElementData(element,"x"),parentY+getElementData(element,"y")
					local width = getElementData(element,"width")
					local height = getElementData(element,"height")
					if (intersect(x,y,x+width,y+height,absoluteX,absoluteY)) then
						triggerEvent("onClientDXDoubleClick",element,button,absoluteX,absoluteY)
					end
				end
			end
		end
	end)
	
addEventHandler("onClientClick",getRootElement(),
	function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedWorld)
		if (isElement(clickedWorld)) then
			local cWorld = string.find(getElementType(clickedWorld),"gui-")
			if (cWorld ~= nil) then
				return
			end
		end
		if (button == "left" and state=="up") then
			for _,element in ipairs(getElementsByType("dxCheckBox")) do
				if dxGetVisible(element) and getElementData(getElementParent(element),"visible") then
					local parentX = getElementData(getElementParent(element),"x")
					local parentY = getElementData(getElementParent(element),"y")
					if (getElementType(getElementParent(element)) == "dxWindow") then
						parentY = parentY + getElementData(getElementData(getElementParent(element),"theme"),"TitleBarTopLeft:Height")-1
					end
					if isCursorShowing() then
						setElementData(element,"hover",false)
						local x,y = 
							parentX+getElementData(element,"x"),parentY+getElementData(element,"y")
						local width = getElementData(element,"width")
						local height = getElementData(element,"height")
						if (intersect(x,y,x+width,y+height,absoluteX,absoluteY)) then
							local checked = not dxCheckBoxGetSelected(element)					
							triggerEvent("onClientDXChanged",element,checked)
							if not wasEventCancelled() then
								dxCheckBoxSetSelected(element,checked)
							end
						end
					end
				end
			end
			
			for _,element in ipairs(getElementsByType("dxRadioButton")) do
				if dxGetVisible(element) and getElementData(getElementParent(element),"visible") then
					local parentX = getElementData(getElementParent(element),"x")
					local parentY = getElementData(getElementParent(element),"y")
					if (getElementType(getElementParent(element)) == "dxWindow") then
						parentY = parentY + getElementData(getElementData(getElementParent(element),"theme"),"TitleBarTopLeft:Height")-1
					end
					if isCursorShowing() then
						setElementData(element,"hover",false)
						local x,y = 
							parentX+getElementData(element,"x"),parentY+getElementData(element,"y")
						local width = getElementData(element,"width")
						local height = getElementData(element,"height")
						if (intersect(x,y,x+width,y+height,absoluteX,absoluteY)) then
							triggerEvent("onClientDXChanged",element,getElementData(element,"group"))
							if not wasEventCancelled() then
								dxRadioButtonSetSelected(element,true)
							end
						end
					end
				end
			end
		end
	end)

addEventHandler("onClientClick",getRootElement(),function(button,state,absoluteX,absoluteY,worldX,worldY,worldZ,clickedWorld)
	if (isElement(clickedWorld)) then
		local cWorld = string.find(getElementType(clickedWorld),"gui-")
		if (cWorld ~= nil) then
			return
		end
	end
	if (button == "left" and state == "down") then
		for _,scrollbar in ipairs(getElementsByType("dxScrollBar")) do
			if (dxGetVisible(scrollbar)) and getElementData(getElementParent(scrollbar),"visible") then
				setElementData(scrollbar,"clicked",false)
				setElementData(scrollbar,"isMoving",false)
				setElementData(scrollbar,"GiveUp",false)
				setElementData(scrollbar,"GiveDown",false)
				local x,y = dxGetPosition(scrollbar)
				local parent = getElementParent(scrollbar)
				local px,py = getElementData(parent,"x"),getElementData(parent,"y")
				local rx,ry = px+x,py+y
				if (getElementType(parent) == "dxWindow") then
					ry = ry + getElementData(dxGetElementTheme(parent),"TitleBarBackground:Height")-1
				end
				local w,h = dxGetSize(scrollbar)
				local cTheme = dxGetElementTheme(scrollbar)
				local type_ = getElementData(scrollbar,"type")
				if ( type_ == "Vertical") then
					local upArrowH=getElementData(cTheme,"ScrollUpArrow:Height")
					local downArrowH=getElementData(cTheme,"ScrollDownArrow:Height")
					local thumb = getElementData(cTheme,"ScrollbarThumb:Height")
					local click,up,down = false
					if (intersect(rx,ry,rx+w,ry+h+upArrowH+downArrowH+thumb,absoluteX,absoluteY)) then
						setElementData(scrollbar,"clicked",true)
						click = true
					end
					
					local ratio = dxScrollBarGetScrollPercent(scrollbar)/50
					local yScroll = ry+upArrowH+(h/2)*ratio
					local c = (w-getElementData(cTheme,"ScrollbarThumb:Width"))/2
					
					if (intersect(rx+c,yScroll,rx+c+getElementData(cTheme,"ScrollbarThumb:Width"),yScroll+thumb,absoluteX,absoluteY)) then
						setElementData(scrollbar,"isMoving",true)
					end
					
					if (intersect(rx,ry,rx+w,ry+upArrowH,absoluteX,absoluteY)) then
						setElementData(scrollbar,"GiveUp",true)
						up = true
					end
					
					if (intersect(rx,ry+upArrowH+h+thumb,rx+w,ry+upArrowH+h+thumb+downArrowH,absoluteX,absoluteY)) then
						setElementData(scrollbar,"GiveDown",true)
						down = true
					end
					
					if (click) and (not up) and (not down) then
						local ay = absoluteY-ry-upArrowH-(thumb/2)
						-- %100'da h ise
						-- y'de	ay'dır
						local y50 = ((ay*100) / h)
						dxScrollBarSetScrollPercent(scrollbar,y50)
					end
				else
					local upArrowW=getElementData(cTheme,"ScrollLeftArrow:Width")
					local downArrowW=getElementData(cTheme,"ScrollRightArrow:Width")
					local thumb = getElementData(cTheme,"ScrollbarThumb:Width")
					local click,up,down = false
					if (intersect(rx,ry,rx+w+upArrowW+thumb+downArrowW,ry+h,absoluteX,absoluteY)) then
						setElementData(scrollbar,"clicked",true)			
						click = true
					end
					
					local ratio = dxScrollBarGetScrollPercent(scrollbar)/50
					local xScroll = rx+upArrowW+(w/2)*ratio
					local c = (h-getElementData(cTheme,"ScrollbarThumb:Height"))/2
					
					if (intersect(xScroll,ry+c,xScroll+getElementData(cTheme,"ScrollbarThumb:Width"),ry+c+getElementData(cTheme,"ScrollbarThumb:Height"),absoluteX,absoluteY)) then
						setElementData(scrollbar,"isMoving",true)
					end
					
					if (intersect(rx,ry,rx+upArrowW,ry+h,absoluteX,absoluteY)) then
						setElementData(scrollbar,"GiveUp",true)
						up = true
					end
					
					if (intersect(rx+upArrowW+w+thumb,ry,rx+upArrowW+w+thumb+downArrowW,ry+h,absoluteX,absoluteY)) then
						setElementData(scrollbar,"GiveDown",true)
						down = true
					end
					if (click) and (not up) and (not down) then
						local ax = absoluteX-rx-upArrowW-(thumb/2)
						-- %100'da w ise
						-- y'de	ax'dır
						local y50 = ((ax*100) / w)
						dxScrollBarSetScrollPercent(scrollbar,y50)
					end
				end
			end
		end
	end
	
	if (button=="left" and state=="up") then
		for _,scrollbar in ipairs(getElementsByType("dxScrollBar")) do
			setElementData(scrollbar,"isMoving",false)
			setElementData(scrollbar,"GiveUp",false)
			setElementData(scrollbar,"GiveDown",false)
		end
	end
end)	

addEventHandler("onClientClick",getRootElement(),function(button,state,absoluteX,absoluteY,worldX,worldY,worldZ,clickedWorld)
	if (isElement(clickedWorld)) then
		local cWorld = string.find(getElementType(clickedWorld),"gui-")
		if (cWorld ~= nil) then
			return
		end
	end
	if (button == "left" and state=="down") then
		for _,spinner in ipairs(getElementsByType("dxSpinner")) do
			if (dxGetVisible(spinner) and getElementData(getElementParent(spinner),"visible")) then
				setElementData(spinner,"clicked",false)
				setElementData(spinner,"increasing",false)
				setElementData(spinner,"increaseRender",false)
				setElementData(spinner,"reducing",false)
				setElementData(spinner,"reduceRender",false)
					
				local x,y = dxGetPosition(spinner)
				local parent = getElementParent(spinner)
				local px,py = getElementData(parent,"x"),getElementData(parent,"y")
				local rx,ry = px+x,py+y
				if (getElementType(parent) == "dxWindow") then
					ry = ry + getElementData(dxGetElementTheme(parent),"TitleBarBackground:Height")-1
				end
				local w,h = dxGetSize(spinner)
				local cTheme = dxGetElementTheme(spinner)
				local optWidth = getElementData(cTheme,"SpinnerIncBackground:Width")	
				if (intersect(rx,ry,rx+w,ry+h,absoluteX,absoluteY)) then
					setElementData(spinner,"clicked",true)
				end
				
				if (intersect(rx+w-optWidth,ry,rx+w,ry+(h/2),absoluteX,absoluteY)) then
					setElementData(spinner,"increasing",true)
				end
				
				if (intersect(rx+w-optWidth,ry+(h/2),rx+w,ry+h,absoluteX,absoluteY)) then
					setElementData(spinner,"reducing",true)
				end
			end
		end
	end
	
	if (button=="left" and state=="up") then
		for _,spinner in ipairs(getElementsByType("dxSpinner")) do
			setElementData(spinner,"increasing",false)
			setElementData(spinner,"increaseRender",false)
			setElementData(spinner,"reducing",false)
			setElementData(spinner,"reduceRender",false)
		end
	end
end)

addEventHandler( "onClientKey", getRootElement(),function(button, press)
	if (button == "mouse_wheel_up") then
		for _,element in ipairs(getElementsByType("dxScrollBar")) do
			if (getElementData(element,"clicked")) then
				local scroll = dxScrollBarGetScroll(element)
				if (scroll > 0) then
					dxScrollBarSetScroll(element,scroll-1)
				end
			end
		end
	elseif (button == "mouse_wheel_down") then
		for _,element in ipairs(getElementsByType("dxScrollBar")) do
			if (getElementData(element,"clicked")) then
				local scroll = dxScrollBarGetScroll(element)
				if (scroll < dxScrollBarGetMaxScroll(element)) then
					dxScrollBarSetScroll(element,scroll+1)
				end
			end
		end
	end
end)

-- dxDrawColorText : by Aiboforcen from mtasa.com
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY)
	if str:sub(1,1) ~= " " then
		str = " "..str
	end
		if alignX then
		if alignX == "center" then
		  local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font)
		  ax = ax + (bx-ax)/2 - w/2
		elseif alignX == "right" then
		  local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font)
		  ax = bx - w
		end
	  end
	 
	  if alignY then
		if alignY == "center" then
		  local h = dxGetFontHeight(scale, font)
		  ay = ay + (by-ay)/2 - h/2
		elseif alignY == "bottom" then
		  local h = dxGetFontHeight(scale, font)
		  ay = by - h
		end
	  end
	 
	  local pat = "(.-)#(%x%x%x%x%x%x)"
	  local s, e, cap, col = str:find(pat, 1)
	  local last = 1
		while s do
		if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end
		if s ~= 1 or cap ~= "" then
		  local w = dxGetTextWidth(cap, scale, font)
		  dxDrawText(cap, ax, ay, ax + w, by, color, scale, font)
		  ax = ax + w
		  color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255)
		end
		last = e + 1
		s, e, cap, col = str:find(pat, last)
	  end
	  if last <= #str then
		cap = str:sub(last)
		local w = dxGetTextWidth(cap, scale, font)
		dxDrawText(cap, ax, ay, ax + w, by, color, scale, font)
	end
end

function dxCreateWindow(x,y,width,height,title,color,font,theme)
	if not x or not y or not width or not height or not title then
		outputDebugString("dxCreateWindow gets wrong parameters. (x,y,width,height,title,[color=white,font=default,theme=dxGetDefaultTheme()]")
		return false
	end
	
	if not color then
		color = tocolor(255,255,255,255)
	end
	
	if not font then
		font = "default"
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateWindow didn't find the main theme.")
		return false
	end
	
	local window = createElement("dxWindow")
	setElementParent(window,dxGetRootPane())
	setElementData(window,"x",x)
	setElementData(window,"y",y)
	setElementData(window,"Title:visible",true)
	setElementData(window,"Title:x",x)
	setElementData(window,"Title:y",y)
	setElementData(window,"colorcoded",false)
	setElementData(window,"width",width)
	setElementData(window,"height",height)
	setElementData(window,"text",title)
	setElementData(window,"color",color)
	setElementData(window,"font",font)
	setElementData(window,"theme",theme)
	setElementData(window,"visible",true)
	setElementData(window,"clicked",false)
	setElementData(window,"movable",true)
	setElementData(window,"isMoving",false)
	setElementData(window,"container",true)
	return window
end

function dxCreateButton(x,y,width,height,text,parent,color,font,theme)
	if not x or not y or not width or not height or not text then
		outputDebugString("dxCreateButton gets wrong parameters (dxElement,x,y,width,height[,parent=dxGetRootPane(),color=white,font=default,theme=dxGetDefaultTheme()])")
		return
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not color then
		color = tocolor(255,255,255,255)
	end
	
	if not font then
		font = "default"
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateButton didn't find the main theme.")
		return false
	end
	
	local button = createElement("dxButton")
	setElementParent(button,parent)
	setElementData(button,"x",x)
	setElementData(button,"y",y)
	setElementData(button,"width",width)
	setElementData(button,"height",height)
	setElementData(button,"text",text)
	setElementData(button,"visible",true)
	setElementData(button,"colorcoded",false)
	setElementData(button,"hover",false)
	setElementData(button,"font",font)
	setElementData(button,"theme",theme)
	setElementData(button,"parent",parent)
	setElementData(button,"container",false)
	return button
end

function dxCreateCheckBox(x,y,width,height,text,selected,parent,color,font,theme)
	if not x or not y or not width or not height or not text then
		outputDebugString("dxCreateCheckBox gets wrong parameters (dxElement,x,y,width,height[,selected=false,parent=dxGetRootPane(),color=white,font=default,theme=dxGetDefaultTheme()])")
		return
	end
	
	if not selected then
		selected = false
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not color then
		color = tocolor(255,255,255,255)
	end
	
	if not font then
		font = "default"
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateCheckBox didn't find the main theme.")
		return false
	end
	
	local checkbox = createElement("dxCheckBox")
	setElementParent(checkbox,parent)
	setElementData(checkbox,"x",x)
	setElementData(checkbox,"y",y)
	setElementData(checkbox,"width",width)
	setElementData(checkbox,"height",height)
	setElementData(checkbox,"text",text)
	setElementData(checkbox,"visible",true)
	setElementData(checkbox,"colorcoded",false)
	setElementData(checkbox,"hover",false)
	setElementData(checkbox,"selected",selected)
	setElementData(checkbox,"font",font)
	setElementData(checkbox,"theme",theme)	
	setElementData(checkbox,"parent",parent)
	setElementData(checkbox,"container",false)
	return checkbox
end

function dxCreateRadioButton(x,y,width,height,text,selected,parent,groupName,color,font,theme)
	if not x or not y or not width or not height or not text then
		outputDebugString("dxCreateRadioButton gets wrong parameters (dxElement,x,y,width,height[,selected=false,parent=dxGetRootPane(),groupName=default,color=white,font=default,theme=dxGetDefaultTheme()])")
		return
	end
	
	if not groupName then
		groupName="default"
	end
	
	if not selected then
		selected = false
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not color then
		color = tocolor(255,255,255,255)
	end
	
	if not font then
		font = "default"
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateCheckBox didn't find the main theme.")
		return false
	end
	
	local radioButton = createElement("dxRadioButton")
	setElementParent(radioButton,parent)
	setElementData(radioButton,"x",x)
	setElementData(radioButton,"y",y)
	setElementData(radioButton,"width",width)
	setElementData(radioButton,"height",height)
	setElementData(radioButton,"text",text)
	setElementData(radioButton,"visible",true)
	setElementData(radioButton,"colorcoded",false)
	setElementData(radioButton,"hover",false)
	setElementData(radioButton,"group",groupName)
	setElementData(radioButton,"font",font)
	setElementData(radioButton,"theme",theme)	
	setElementData(radioButton,"parent",parent)
	setElementData(radioButton,"container",false)
	dxRadioButtonSetSelected(radioButton,selected)
	return radioButton
end

function dxCreateLabel(x,y,width,height,text,parent,color,font,scale,alignX,alignY,colorCoded)
	if not x or not y or not width or not height or not text then
		outputDebugString("dxCreateLabel gets wrong parameters (dxElement,x,y,width,height[,parent=dxGetRootPane(),color=white,font=default,scale=1,alignX=left,alignY=top,colorCoded=false])")
		return
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not color then
		color = tocolor(255,255,255,255)
	end
	
	if not font then
		font = "default"
	end
	
	if not colorCoded then
		colorCoded = false
	end
	
	if not scale then
		scale = 1
	end
	
	if not alignX then
		alignX = "left"
	end
	
	if not alignY then
		alignY = "top"
	end
	
	local label = createElement("dxLabel")
	setElementParent(label,parent)
	setElementData(label,"x",x)
	setElementData(label,"y",y)
	setElementData(label,"width",width)
	setElementData(label,"height",height)
	setElementData(label,"text",text)
	setElementData(label,"visible",true)
	setElementData(label,"colorcoded",colorCoded)
	setElementData(label,"hover",false)
	setElementData(label,"scale",scale)
	setElementData(label,"font",font)
	setElementData(label,"alignX",alignX)
	setElementData(label,"alignY",alignY)
	setElementData(label,"parent",parent)
	setElementData(label,"container",false)
	return label
end

function dxCreateStaticImage(x,y,width,height,path,rotation,parent)
	if not x or not y or not width or not height or not path then
		outputDebugString("dxCreateStaticImage gets wrong parameters (dxElement,x,y,width,height,path[,rotation=0,parent=dxGetRootPane()])")
		return
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not rotation then
		rotation = 0
	end
	if not fileExists(path) then
		return false
	end
	
	local image = createElement("dxStaticImage")
	setElementParent(image,parent)
	setElementData(image,"x",x)
	setElementData(image,"y",y)
	setElementData(image,"width",width)
	setElementData(image,"height",height)
	setElementData(image,"rotation",rotation)
	setElementData(image,"Section",false)
	setElementData(image,"Section:x",false)
	setElementData(image,"Section:y",false)
	setElementData(image,"Section:width",false)
	setElementData(image,"Section:height",false)
	setElementData(image,"image",path)
	setElementData(image,"visible",true)
	setElementData(image,"hover",false)
	setElementData(image,"parent",parent)
	setElementData(image,"container",false)
	return image
end

function dxCreateStaticImageSection(x,y,width,height,sectionX,sectionY,sectionWidth,sectionHeight,path,rotation,parent)
	if not x or not y or not width or not height or not path or not sectionX or not sectionY or not sectionWidth or not sectionHeight then
		outputDebugString("dxCreateStaticImageSection gets wrong parameters (dxElement,x,y,width,height,sectionX,sectionY,sectionWidth,sectionHeight,path[,rotation=0,parent=dxGetRootPane()])")
		return
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	if not rotation then
		rotation = 0
	end
	if not fileExists(path) then
		return false
	end
	
	local image = createElement("dxStaticImage")
	setElementParent(image,parent)
	setElementData(image,"x",x)
	setElementData(image,"y",y)
	setElementData(image,"width",width)
	setElementData(image,"height",height)
	setElementData(image,"rotation",rotation)
	setElementData(image,"Section",true)
	setElementData(image,"Section:x",sectionX)
	setElementData(image,"Section:y",sectionY)
	setElementData(image,"Section:width",sectionWidth)
	setElementData(image,"Section:height",sectionHeight)
	setElementData(image,"image",path)
	setElementData(image,"visible",true)
	setElementData(image,"hover",false)
	setElementData(image,"parent",parent)
	setElementData(image,"container",false)
	return image
end

function dxCreateProgressBar(x,y,width,height,parent,progress,color,max_,theme)
	if not x or not y or not width or not height then
		outputDebugString("dxCreateProgressBar gets wrong parameters (x,y,width,height[,parent=dxGetRootPane(),progress=0,color=segment,max=100,theme=dxGetDefaultTheme()])")
		return
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not progress then
		progress = 0
	end
	
	if not max_ then
		max_ = 100
	end
	
	if max_ <= 0 then
		max_ = 100
	end
	
	if progress < 0 or progress > max_ then
		progress = 0
	end
	
	if not color then
		color = "segment"
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateCheckBox didn't find the main theme.")
		return false
	end
	
	local progressBar = createElement("dxProgressBar")
	setElementParent(progressBar,parent)
	setElementData(progressBar,"x",x)
	setElementData(progressBar,"y",y)
	setElementData(progressBar,"width",width)
	setElementData(progressBar,"height",height)
	setElementData(progressBar,"progress",progress)
	setElementData(progressBar,"max",max_)
	setElementData(progressBar,"theme",theme)
	setElementData(progressBar,"visible",true)
	setElementData(progressBar,"progressColor",color)
	setElementData(progressBar,"hover",false)
	setElementData(progressBar,"parent",parent)
	setElementData(progressBar,"container",false)
	return progressBar
end

function dxCreateScrollBar(x,y,width,height,parent,type_,progress,max_,theme)
	if not x or not y or not width or not height then
		outputDebugString("dxCreateScrollBar gets wrong parameters (x,y,width,height[,parent=dxGetRootPane(),type=Vertical,scroll=0,max=100,theme=dxGetDefaultTheme()])")
		return
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if type_ == nil then
		type_ = "Vertical"
	end
	
	if type_ ~= "Vertical" and type_ ~= "Horizontal" and type_ ~= 0 and type_~= 1 then
		type_ = "Vertical"
	end
	
	if (type_ == 0) then
		type_ = "Vertical"
	end
	
	if (type_ == 1) then
		type_ = "Horizontal"
	end
	
	if not progress then
		progress = 0
	end
	
	if not max_ then
		max_ = 100
	end
	
	if max_ <= 0 then
		max_ = 100
	end
	
	if progress < 0 or progress > max_ then
		progress = 0
	end
	
	if not color then
		color = "segment"
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateScrollBar didn't find the main theme.")
		return false
	end
	
	local scrollBar = createElement("dxScrollBar")
	setElementParent(scrollBar,parent)
	setElementData(scrollBar,"x",x)
	setElementData(scrollBar,"y",y)
	setElementData(scrollBar,"width",width)
	setElementData(scrollBar,"height",height)
	setElementData(scrollBar,"type",type_)
	setElementData(scrollBar,"progress",progress)
	setElementData(scrollBar,"max",max_)
	setElementData(scrollBar,"theme",theme)
	setElementData(scrollBar,"visible",true)
	setElementData(scrollBar,"hover",false)
	setElementData(scrollBar,"parent",parent)
	setElementData(scrollBar,"container",false)
	return scrollBar
end

function dxCreateSpinner(x,y,width,height,parent,color,defaultPos,min_,max_,theme)
	if not x or not y or not width or not height then
		outputDebugString("dxCreateSpinner gets wrong parameters (x,y,width,height[parent=dxGetRootPane(),color=black,defaultPos=0,min=0,max=100,font=default,theme=dxGetDefaultTheme()])")
		return
	end
	
	if not color then
		color = tocolor(0,0,0,255)
	end
	
	if not font then
		font = "default"
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not defaultPos then
		defaultPos = 0
	end
	
	if not min_ then
		min_ = 0
	end
	
	if not max_ then
		max_ = 100
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateSpinner didn't find the main theme.")
		return false
	end
	
	local spinner = createElement("dxSpinner")
	setElementParent(spinner,parent)
	setElementData(spinner,"x",x)
	setElementData(spinner,"y",y)
	setElementData(spinner,"width",width)
	setElementData(spinner,"height",height)
	setElementData(spinner,"max",max_)
	setElementData(spinner,"position",defaultPos)
	setElementData(spinner,"min",min_)
	setElementData(spinner,"theme",theme)
	setElementData(spinner,"color",color)
	setElementData(spinner,"font",font)
	setElementData(spinner,"visible",true)
	setElementData(spinner,"hover",false)
	setElementData(spinner,"parent",parent)
	setElementData(spinner,"container",false)
	return spinner
end

addEvent("onClientDXMouseEnter",false)
addEvent("onClientDXMouseLeave",false)
addEvent("onClientDXClick",false)
addEvent("onClientDXChanged",false)
addEvent("onClientDXPropertyChanged",false)
addEvent("onClientDXScroll",false)
addEvent("onClientDXDoubleClick",false)
addEvent("onClientDXSpin",false)

--[[function dxCreateEdit(x,y,width,height,text,placeholder,parent,color,font,theme)
	if not x or not y or not width or not height or not text then
		outputDebugString("dxCreateEdit gets wrong parameters (x,y,width,height,text[,placeholder=none,parent=dxGetRootPane(),color=white,font=default,theme=dxGetDefaultTheme()])")
		return
	end
	
	if not parent then
		parent = dxGetRootPane()
	end
	
	if not font then
		font = "default"
	end
	
	if not placeholder then
		placeholder = ""
	end
	
	if not color then
		color = tocolor(255,255,255,255)
	end
	
	if not theme then
		theme = dxGetDefaultTheme()
	end
	
	if type(theme) == "string" then
		theme = dxGetTheme(theme)
	end
	
	if not theme then
		outputDebugString("dxCreateEdit didn't find the main theme.")
		return false
	end
	
	local edit = createElement("dxEdit")
	setElementParent(edit,parent)
	setElementData(edit,"x",x)
	setElementData(edit,"y",y)
	setElementData(edit,"width",width)
	setElementData(edit,"height",height)
	setElementData(edit,"color",color)
	setElementData(edit,"font",font)
	setElementData(edit,"placeholder",placeholder)
	setElementData(edit,"theme",theme)
	setElementData(edit,"visible",true)
	setElementData(edit,"text",text)
	setElementData(edit,"hover",false)
	setElementData(edit,"parent",parent)
	setElementData(edit,"readonly",false)
	setElementData(edit,"caret",-1)
	setElementData(edit,"masked",false)
	setElementData(edit,"maxlength",-1)
	return edit
end

function dxProgressBarGetMaxProgress(dxElement)
	if not dxElement then
		outputDebugString("dxProgressBarGetMaxProgress gets wrong parameters.(dxElement)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarGetMaxProgress gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	return getElementData(dxElement,"max")
end

function dxProgressBarSetMaxProgress(dxElement,progress)
	if not dxElement or not progress then
		outputDebugString("dxProgressBarSetMaxProgress gets wrong parameters.(dxElement,maxProgress)")
		return
	end
	if (getElementType(dxElement)~="dxProgressBar") then
		outputDebugString("dxProgressBarSetMaxProgress gets wrong parameters.(dxElement must be dxProgressBar)")
		return
	end
	setElementData(dxElement,"max",progress)
	if (getElementData(dxElement,"progress") > progress ) then
		dxProgressBarSetProgress(dxElement,progress)
	end
end

function dxEditGetPlaceholder(dxElement)
	if not dxElement then
		outputChatBox("dxEditGetPlaceholder gets wrong parameters(dxElement)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditGetPlaceholder gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"placeholder")
end

function dxEditGetCaret(dxElement)
	if not dxElement then
		outputChatBox("dxEditGetCaret gets wrong parameters(dxElement)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditGetCaret gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"caret")
end

function dxEditIsReadOnly(dxElement)
	if not dxElement then
		outputChatBox("dxEditIsReadOnly gets wrong parameters(dxElement)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditIsReadOnly gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"readonly")
end

function dxEditIsMasked(dxElement)
	if not dxElement then
		outputChatBox("dxEditIsMasked gets wrong parameters(dxElement)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditIsMasked gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"masked")
end

function dxEditGetMaxLength(dxElement)
	if not dxElement then
		outputChatBox("dxEditGetMaxLength gets wrong parameters(dxElement)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditGetMaxLength gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	return getElementData(dxElement,"maxlength")
end

--
function dxEditSetPlaceholder(dxElement,placeholder)
	if not dxElement or not placeholder then
		outputChatBox("dxEditSetPlaceholder gets wrong parameters(dxElement,placeholder)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditSetPlaceholder gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"placeholder",placeholder)
end

function dxEditSetCaret(dxElement,caret)
	if not dxElement or not caret then
		outputChatBox("dxEditSetCaret gets wrong parameters(dxElement,caret)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditSetCaret gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"caret",caret)
end

function dxEditSetReadOnly(dxElement,readonly)
	if not dxElement or readonly == nil then
		outputChatBox("dxEditSetReadOnly gets wrong parameters(dxElement,readonly)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditSetReadOnly gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"readonly",readonly)
end

function dxEditSetMasked(dxElement,masked)
	if not dxElement or masked == nil then
		outputChatBox("dxEditSetMasked gets wrong parameters(dxElement)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditSetMasked gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"masked",masked)
end

function dxEditSetMaxLength(dxElement,maxlen)
	if not dxElement or not maxlen then
		outputChatBox("dxEditSetMaxLength gets wrong parameters(dxElement,maxlength)")
		return
	end
	if getElementType(dxElement) ~= "dxEdit" then
		outputChatBox("dxEditSetMaxLength gets wrong parameters(dxElement must be dxLabel)")
		return
	end
	setElementData(dxElement,"maxlength",maxlength)
end]]